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

Side by Side Diff: src/messages.js

Issue 6349018: Avoid using Function.prototype.call in a number of places in our (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 10 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/json.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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 var kCapitalVowelSounds = 0; 43 var kCapitalVowelSounds = 0;
44 44
45 // Matches Messages::kNoLineNumberInfo from v8.h 45 // Matches Messages::kNoLineNumberInfo from v8.h
46 var kNoLineNumberInfo = 0; 46 var kNoLineNumberInfo = 0;
47 47
48 // If this object gets passed to an error constructor the error will 48 // If this object gets passed to an error constructor the error will
49 // get an accessor for .message that constructs a descriptive error 49 // get an accessor for .message that constructs a descriptive error
50 // message on access. 50 // message on access.
51 var kAddMessageAccessorsMarker = { }; 51 var kAddMessageAccessorsMarker = { };
52 52
53
54 function GetInstanceName(cons) {
55 if (cons.length == 0) {
56 return "";
57 }
58 var first = %StringToLowerCase(StringCharAt.call(cons, 0));
59 if (kVowelSounds === 0) {
60 kVowelSounds = {a: true, e: true, i: true, o: true, u: true, y: true};
61 kCapitalVowelSounds = {a: true, e: true, i: true, o: true, u: true, h: true,
62 f: true, l: true, m: true, n: true, r: true, s: true, x: true, y: true};
63 }
64 var vowel_mapping = kVowelSounds;
65 if (cons.length > 1 && (StringCharAt.call(cons, 0) != first)) {
66 // First char is upper case
67 var second = %StringToLowerCase(StringCharAt.call(cons, 1));
68 // Second char is upper case
69 if (StringCharAt.call(cons, 1) != second) {
70 vowel_mapping = kCapitalVowelSounds;
71 }
72 }
73 var s = vowel_mapping[first] ? "an " : "a ";
74 return s + cons;
75 }
76
77
78 var kMessages = 0; 53 var kMessages = 0;
79 54
55 var kReplacementMarkers =
56 [ "%0", "%1", "%2", "%3", "%4", "%5", "%6", "%7", "%8", "%9", "%10" ];
80 57
81 function FormatString(format, args) { 58 function FormatString(format, args) {
82 var result = format; 59 var result = format;
83 for (var i = 0; i < args.length; i++) { 60 for (var i = 0; i < args.length; i++) {
84 var str; 61 var str;
85 try { 62 try {
86 str = ToDetailString(args[i]); 63 str = ToDetailString(args[i]);
87 } catch (e) { 64 } catch (e) {
88 str = "#<error>"; 65 str = "#<error>";
89 } 66 }
90 result = ArrayJoin.call(StringSplit.call(result, "%" + i), str); 67 var replacement_marker = kReplacementMarkers[i];
68 var split = %_CallFunction(result, replacement_marker, StringSplit);
69 result = %_CallFunction(split, str, ArrayJoin);
91 } 70 }
92 return result; 71 return result;
93 } 72 }
94 73
95 74
96 // To check if something is a native error we need to check the 75 // To check if something is a native error we need to check the
97 // concrete native error types. It is not enough to check "obj 76 // concrete native error types. It is not enough to check "obj
98 // instanceof $Error" because user code can replace 77 // instanceof $Error" because user code can replace
99 // NativeError.prototype.__proto__. User code cannot replace 78 // NativeError.prototype.__proto__. User code cannot replace
100 // NativeError.prototype though and therefore this is a safe test. 79 // NativeError.prototype though and therefore this is a safe test.
(...skipping 22 matching lines...) Expand all
123 102
124 103
125 function ToDetailString(obj) { 104 function ToDetailString(obj) {
126 if (obj != null && IS_OBJECT(obj) && obj.toString === $Object.prototype.toStri ng) { 105 if (obj != null && IS_OBJECT(obj) && obj.toString === $Object.prototype.toStri ng) {
127 var constructor = obj.constructor; 106 var constructor = obj.constructor;
128 if (!constructor) return ToStringCheckErrorObject(obj); 107 if (!constructor) return ToStringCheckErrorObject(obj);
129 var constructorName = constructor.name; 108 var constructorName = constructor.name;
130 if (!constructorName || !IS_STRING(constructorName)) { 109 if (!constructorName || !IS_STRING(constructorName)) {
131 return ToStringCheckErrorObject(obj); 110 return ToStringCheckErrorObject(obj);
132 } 111 }
133 return "#<" + GetInstanceName(constructorName) + ">"; 112 return "#<" + constructorName + ">";
134 } else { 113 } else {
135 return ToStringCheckErrorObject(obj); 114 return ToStringCheckErrorObject(obj);
136 } 115 }
137 } 116 }
138 117
139 118
140 function MakeGenericError(constructor, type, args) { 119 function MakeGenericError(constructor, type, args) {
141 if (IS_UNDEFINED(args)) { 120 if (IS_UNDEFINED(args)) {
142 args = []; 121 args = [];
143 } 122 }
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 */ 324 */
346 Script.prototype.locationFromPosition = function (position, 325 Script.prototype.locationFromPosition = function (position,
347 include_resource_offset) { 326 include_resource_offset) {
348 var line = this.lineFromPosition(position); 327 var line = this.lineFromPosition(position);
349 if (line == -1) return null; 328 if (line == -1) return null;
350 329
351 // Determine start, end and column. 330 // Determine start, end and column.
352 var line_ends = this.line_ends; 331 var line_ends = this.line_ends;
353 var start = line == 0 ? 0 : line_ends[line - 1] + 1; 332 var start = line == 0 ? 0 : line_ends[line - 1] + 1;
354 var end = line_ends[line]; 333 var end = line_ends[line];
355 if (end > 0 && StringCharAt.call(this.source, end - 1) == '\r') end--; 334 if (end > 0 && %_CallFunction(this.source, end - 1, StringCharAt) == '\r') end --;
356 var column = position - start; 335 var column = position - start;
357 336
358 // Adjust according to the offset within the resource. 337 // Adjust according to the offset within the resource.
359 if (include_resource_offset) { 338 if (include_resource_offset) {
360 line += this.line_offset; 339 line += this.line_offset;
361 if (line == this.line_offset) { 340 if (line == this.line_offset) {
362 column += this.column_offset; 341 column += this.column_offset;
363 } 342 }
364 } 343 }
365 344
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 439
461 // Check parameter. 440 // Check parameter.
462 if (line < 0 || this.lineCount() <= line) { 441 if (line < 0 || this.lineCount() <= line) {
463 return null; 442 return null;
464 } 443 }
465 444
466 // Return the source line. 445 // Return the source line.
467 var line_ends = this.line_ends; 446 var line_ends = this.line_ends;
468 var start = line == 0 ? 0 : line_ends[line - 1] + 1; 447 var start = line == 0 ? 0 : line_ends[line - 1] + 1;
469 var end = line_ends[line]; 448 var end = line_ends[line];
470 return StringSubstring.call(this.source, start, end); 449 return %_CallFunction(this.source, start, end, StringSubstring);
471 } 450 }
472 451
473 452
474 /** 453 /**
475 * Returns the number of source lines. 454 * Returns the number of source lines.
476 * @return {number} 455 * @return {number}
477 * Number of source lines. 456 * Number of source lines.
478 */ 457 */
479 Script.prototype.lineCount = function() { 458 Script.prototype.lineCount = function() {
480 // Return number of source lines. 459 // Return number of source lines.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 } 567 }
589 }; 568 };
590 569
591 570
592 /** 571 /**
593 * Get the source text for a SourceLocation 572 * Get the source text for a SourceLocation
594 * @return {String} 573 * @return {String}
595 * Source text for this location. 574 * Source text for this location.
596 */ 575 */
597 SourceLocation.prototype.sourceText = function () { 576 SourceLocation.prototype.sourceText = function () {
598 return StringSubstring.call(this.script.source, this.start, this.end); 577 return %_CallFunction(this.script.source, this.start, this.end, StringSubstrin g);
599 }; 578 };
600 579
601 580
602 /** 581 /**
603 * Class for a source slice. A source slice is a part of a script source with 582 * Class for a source slice. A source slice is a part of a script source with
604 * the following properties: 583 * the following properties:
605 * script : script object for the source 584 * script : script object for the source
606 * from_line : line number for the first line in the slice 585 * from_line : line number for the first line in the slice
607 * to_line : source line number for the last line in the slice 586 * to_line : source line number for the last line in the slice
608 * from_position : position of the first character in the slice 587 * from_position : position of the first character in the slice
(...skipping 16 matching lines...) Expand all
625 this.to_position = to_position; 604 this.to_position = to_position;
626 } 605 }
627 606
628 607
629 /** 608 /**
630 * Get the source text for a SourceSlice 609 * Get the source text for a SourceSlice
631 * @return {String} Source text for this slice. The last line will include 610 * @return {String} Source text for this slice. The last line will include
632 * the line terminating characters (if any) 611 * the line terminating characters (if any)
633 */ 612 */
634 SourceSlice.prototype.sourceText = function () { 613 SourceSlice.prototype.sourceText = function () {
635 return StringSubstring.call(this.script.source, this.from_position, this.to_po sition); 614 return %_CallFunction(this.script.source,
615 this.from_position,
616 this.to_position,
617 StringSubstring);
636 }; 618 };
637 619
638 620
639 // Returns the offset of the given position within the containing 621 // Returns the offset of the given position within the containing
640 // line. 622 // line.
641 function GetPositionInLine(message) { 623 function GetPositionInLine(message) {
642 var location = message.script.locationFromPosition(message.startPos, false); 624 var location = message.script.locationFromPosition(message.startPos, false);
643 if (location == null) return -1; 625 if (location == null) return -1;
644 location.restrict(); 626 location.restrict();
645 return message.startPos - location.start; 627 return message.startPos - location.start;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 this.pos = pos; 682 this.pos = pos;
701 } 683 }
702 684
703 CallSite.prototype.getThis = function () { 685 CallSite.prototype.getThis = function () {
704 return this.receiver; 686 return this.receiver;
705 }; 687 };
706 688
707 CallSite.prototype.getTypeName = function () { 689 CallSite.prototype.getTypeName = function () {
708 var constructor = this.receiver.constructor; 690 var constructor = this.receiver.constructor;
709 if (!constructor) 691 if (!constructor)
710 return $Object.prototype.toString.call(this.receiver); 692 return %_CallFunction(this.receiver, ObjectToString);
711 var constructorName = constructor.name; 693 var constructorName = constructor.name;
712 if (!constructorName) 694 if (!constructorName)
713 return $Object.prototype.toString.call(this.receiver); 695 return %_CallFunction(this.receiver, ObjectToString);
714 return constructorName; 696 return constructorName;
715 }; 697 };
716 698
717 CallSite.prototype.isToplevel = function () { 699 CallSite.prototype.isToplevel = function () {
718 if (this.receiver == null) 700 if (this.receiver == null)
719 return true; 701 return true;
720 return IS_GLOBAL(this.receiver); 702 return IS_GLOBAL(this.receiver);
721 }; 703 };
722 704
723 CallSite.prototype.isEval = function () { 705 CallSite.prototype.isEval = function () {
(...skipping 28 matching lines...) Expand all
752 if (script && script.compilation_type == COMPILATION_TYPE_EVAL) 734 if (script && script.compilation_type == COMPILATION_TYPE_EVAL)
753 return "eval"; 735 return "eval";
754 return null; 736 return null;
755 }; 737 };
756 738
757 CallSite.prototype.getMethodName = function () { 739 CallSite.prototype.getMethodName = function () {
758 // See if we can find a unique property on the receiver that holds 740 // See if we can find a unique property on the receiver that holds
759 // this function. 741 // this function.
760 var ownName = this.fun.name; 742 var ownName = this.fun.name;
761 if (ownName && this.receiver && 743 if (ownName && this.receiver &&
762 (ObjectLookupGetter.call(this.receiver, ownName) === this.fun || 744 (%_CallFunction(this.receiver, ownName, ObjectLookupGetter) === this.fun | |
763 ObjectLookupSetter.call(this.receiver, ownName) === this.fun || 745 %_CallFunction(this.receiver, ownName, ObjectLookupSetter) === this.fun | |
764 this.receiver[ownName] === this.fun)) { 746 this.receiver[ownName] === this.fun)) {
765 // To handle DontEnum properties we guess that the method has 747 // To handle DontEnum properties we guess that the method has
766 // the same name as the function. 748 // the same name as the function.
767 return ownName; 749 return ownName;
768 } 750 }
769 var name = null; 751 var name = null;
770 for (var prop in this.receiver) { 752 for (var prop in this.receiver) {
771 if (this.receiver.__lookupGetter__(prop) === this.fun || 753 if (this.receiver.__lookupGetter__(prop) === this.fun ||
772 this.receiver.__lookupSetter__(prop) === this.fun || 754 this.receiver.__lookupSetter__(prop) === this.fun ||
773 (!this.receiver.__lookupGetter__(prop) && this.receiver[prop] === this.f un)) { 755 (!this.receiver.__lookupGetter__(prop) && this.receiver[prop] === this.f un)) {
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 else throw e; 1063 else throw e;
1082 } 1064 }
1083 } 1065 }
1084 1066
1085 %FunctionSetName(errorToString, 'toString'); 1067 %FunctionSetName(errorToString, 'toString');
1086 %SetProperty($Error.prototype, 'toString', errorToString, DONT_ENUM); 1068 %SetProperty($Error.prototype, 'toString', errorToString, DONT_ENUM);
1087 1069
1088 // Boilerplate for exceptions for stack overflows. Used from 1070 // Boilerplate for exceptions for stack overflows. Used from
1089 // Top::StackOverflow(). 1071 // Top::StackOverflow().
1090 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); 1072 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []);
OLDNEW
« no previous file with comments | « src/json.js ('k') | src/mirror-debugger.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698