| OLD | NEW |
| 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 (function(global, utils) { | 7 (function(global, utils) { |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 } | 84 } |
| 85 | 85 |
| 86 | 86 |
| 87 function NoSideEffectToString(obj) { | 87 function NoSideEffectToString(obj) { |
| 88 if (IS_STRING(obj)) return obj; | 88 if (IS_STRING(obj)) return obj; |
| 89 if (IS_NUMBER(obj)) return %_NumberToString(obj); | 89 if (IS_NUMBER(obj)) return %_NumberToString(obj); |
| 90 if (IS_BOOLEAN(obj)) return obj ? 'true' : 'false'; | 90 if (IS_BOOLEAN(obj)) return obj ? 'true' : 'false'; |
| 91 if (IS_UNDEFINED(obj)) return 'undefined'; | 91 if (IS_UNDEFINED(obj)) return 'undefined'; |
| 92 if (IS_NULL(obj)) return 'null'; | 92 if (IS_NULL(obj)) return 'null'; |
| 93 if (IS_FUNCTION(obj)) { | 93 if (IS_FUNCTION(obj)) { |
| 94 var str = %_CallFunction(obj, obj, FunctionSourceString); | 94 var str = %_Call(FunctionSourceString, obj, obj); |
| 95 if (str.length > 128) { | 95 if (str.length > 128) { |
| 96 str = %_SubString(str, 0, 111) + "...<omitted>..." + | 96 str = %_SubString(str, 0, 111) + "...<omitted>..." + |
| 97 %_SubString(str, str.length - 2, str.length); | 97 %_SubString(str, str.length - 2, str.length); |
| 98 } | 98 } |
| 99 return str; | 99 return str; |
| 100 } | 100 } |
| 101 if (IS_SYMBOL(obj)) return %_CallFunction(obj, SymbolToString); | 101 if (IS_SYMBOL(obj)) return %_Call(SymbolToString, obj); |
| 102 if (IS_SIMD_VALUE(obj)) { | 102 if (IS_SIMD_VALUE(obj)) { |
| 103 switch (typeof(obj)) { | 103 switch (typeof(obj)) { |
| 104 case 'float32x4': return %_CallFunction(obj, Float32x4ToString); | 104 case 'float32x4': return %_Call(Float32x4ToString, obj); |
| 105 case 'int32x4': return %_CallFunction(obj, Int32x4ToString); | 105 case 'int32x4': return %_Call(Int32x4ToString, obj); |
| 106 case 'int16x8': return %_CallFunction(obj, Int16x8ToString); | 106 case 'int16x8': return %_Call(Int16x8ToString, obj); |
| 107 case 'int8x16': return %_CallFunction(obj, Int8x16ToString); | 107 case 'int8x16': return %_Call(Int8x16ToString, obj); |
| 108 case 'uint32x4': return %_CallFunction(obj, Uint32x4ToString); | 108 case 'uint32x4': return %_Call(Uint32x4ToString, obj); |
| 109 case 'uint16x8': return %_CallFunction(obj, Uint16x8ToString); | 109 case 'uint16x8': return %_Call(Uint16x8ToString, obj); |
| 110 case 'uint8x16': return %_CallFunction(obj, Uint8x16ToString); | 110 case 'uint8x16': return %_Call(Uint8x16ToString, obj); |
| 111 case 'bool32x4': return %_CallFunction(obj, Bool32x4ToString); | 111 case 'bool32x4': return %_Call(Bool32x4ToString, obj); |
| 112 case 'bool16x8': return %_CallFunction(obj, Bool16x8ToString); | 112 case 'bool16x8': return %_Call(Bool16x8ToString, obj); |
| 113 case 'bool8x16': return %_CallFunction(obj, Bool8x16ToString); | 113 case 'bool8x16': return %_Call(Bool8x16ToString, obj); |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 if (IS_OBJECT(obj) | 116 if (IS_OBJECT(obj) |
| 117 && %GetDataProperty(obj, "toString") === ObjectToString) { | 117 && %GetDataProperty(obj, "toString") === ObjectToString) { |
| 118 var constructor = %GetDataProperty(obj, "constructor"); | 118 var constructor = %GetDataProperty(obj, "constructor"); |
| 119 if (typeof constructor == "function") { | 119 if (typeof constructor == "function") { |
| 120 var constructorName = constructor.name; | 120 var constructorName = constructor.name; |
| 121 if (IS_STRING(constructorName) && constructorName !== "") { | 121 if (IS_STRING(constructorName) && constructorName !== "") { |
| 122 return "#<" + constructorName + ">"; | 122 return "#<" + constructorName + ">"; |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 if (CanBeSafelyTreatedAsAnErrorObject(obj)) { | 126 if (CanBeSafelyTreatedAsAnErrorObject(obj)) { |
| 127 return %_CallFunction(obj, ErrorToString); | 127 return %_Call(ErrorToString, obj); |
| 128 } | 128 } |
| 129 | 129 |
| 130 return %_CallFunction(obj, NoSideEffectsObjectToString); | 130 return %_Call(NoSideEffectsObjectToString, obj); |
| 131 } | 131 } |
| 132 | 132 |
| 133 // To determine whether we can safely stringify an object using ErrorToString | 133 // To determine whether we can safely stringify an object using ErrorToString |
| 134 // without the risk of side-effects, we need to check whether the object is | 134 // without the risk of side-effects, we need to check whether the object is |
| 135 // either an instance of a native error type (via '%_ClassOf'), or has Error | 135 // either an instance of a native error type (via '%_ClassOf'), or has Error |
| 136 // in its prototype chain and hasn't overwritten 'toString' with something | 136 // in its prototype chain and hasn't overwritten 'toString' with something |
| 137 // strange and unusual. | 137 // strange and unusual. |
| 138 function CanBeSafelyTreatedAsAnErrorObject(obj) { | 138 function CanBeSafelyTreatedAsAnErrorObject(obj) { |
| 139 switch (%_ClassOf(obj)) { | 139 switch (%_ClassOf(obj)) { |
| 140 case 'Error': | 140 case 'Error': |
| (...skipping 10 matching lines...) Expand all Loading... |
| 151 return obj instanceof GlobalError && objToString === ErrorToString; | 151 return obj instanceof GlobalError && objToString === ErrorToString; |
| 152 } | 152 } |
| 153 | 153 |
| 154 | 154 |
| 155 // When formatting internally created error messages, do not | 155 // When formatting internally created error messages, do not |
| 156 // invoke overwritten error toString methods but explicitly use | 156 // invoke overwritten error toString methods but explicitly use |
| 157 // the error to string method. This is to avoid leaking error | 157 // the error to string method. This is to avoid leaking error |
| 158 // objects between script tags in a browser setting. | 158 // objects between script tags in a browser setting. |
| 159 function ToStringCheckErrorObject(obj) { | 159 function ToStringCheckErrorObject(obj) { |
| 160 if (CanBeSafelyTreatedAsAnErrorObject(obj)) { | 160 if (CanBeSafelyTreatedAsAnErrorObject(obj)) { |
| 161 return %_CallFunction(obj, ErrorToString); | 161 return %_Call(ErrorToString, obj); |
| 162 } else { | 162 } else { |
| 163 return TO_STRING(obj); | 163 return TO_STRING(obj); |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 | 166 |
| 167 | 167 |
| 168 function ToDetailString(obj) { | 168 function ToDetailString(obj) { |
| 169 if (obj != null && IS_OBJECT(obj) && obj.toString === ObjectToString) { | 169 if (obj != null && IS_OBJECT(obj) && obj.toString === ObjectToString) { |
| 170 var constructor = obj.constructor; | 170 var constructor = obj.constructor; |
| 171 if (typeof constructor == "function") { | 171 if (typeof constructor == "function") { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 */ | 289 */ |
| 290 function ScriptLocationFromPosition(position, | 290 function ScriptLocationFromPosition(position, |
| 291 include_resource_offset) { | 291 include_resource_offset) { |
| 292 var line = this.lineFromPosition(position); | 292 var line = this.lineFromPosition(position); |
| 293 if (line == -1) return null; | 293 if (line == -1) return null; |
| 294 | 294 |
| 295 // Determine start, end and column. | 295 // Determine start, end and column. |
| 296 var line_ends = this.line_ends; | 296 var line_ends = this.line_ends; |
| 297 var start = line == 0 ? 0 : line_ends[line - 1] + 1; | 297 var start = line == 0 ? 0 : line_ends[line - 1] + 1; |
| 298 var end = line_ends[line]; | 298 var end = line_ends[line]; |
| 299 if (end > 0 && %_CallFunction(this.source, end - 1, StringCharAt) == '\r') { | 299 if (end > 0 && %_Call(StringCharAt, this.source, end - 1) == '\r') { |
| 300 end--; | 300 end--; |
| 301 } | 301 } |
| 302 var column = position - start; | 302 var column = position - start; |
| 303 | 303 |
| 304 // Adjust according to the offset within the resource. | 304 // Adjust according to the offset within the resource. |
| 305 if (include_resource_offset) { | 305 if (include_resource_offset) { |
| 306 line += this.line_offset; | 306 line += this.line_offset; |
| 307 if (line == this.line_offset) { | 307 if (line == this.line_offset) { |
| 308 column += this.column_offset; | 308 column += this.column_offset; |
| 309 } | 309 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 | 412 |
| 413 // Check parameter. | 413 // Check parameter. |
| 414 if (line < 0 || this.lineCount() <= line) { | 414 if (line < 0 || this.lineCount() <= line) { |
| 415 return null; | 415 return null; |
| 416 } | 416 } |
| 417 | 417 |
| 418 // Return the source line. | 418 // Return the source line. |
| 419 var line_ends = this.line_ends; | 419 var line_ends = this.line_ends; |
| 420 var start = line == 0 ? 0 : line_ends[line - 1] + 1; | 420 var start = line == 0 ? 0 : line_ends[line - 1] + 1; |
| 421 var end = line_ends[line]; | 421 var end = line_ends[line]; |
| 422 return %_CallFunction(this.source, start, end, StringSubstring); | 422 return %_Call(StringSubstring, this.source, start, end); |
| 423 } | 423 } |
| 424 | 424 |
| 425 | 425 |
| 426 /** | 426 /** |
| 427 * Returns the number of source lines. | 427 * Returns the number of source lines. |
| 428 * @return {number} | 428 * @return {number} |
| 429 * Number of source lines. | 429 * Number of source lines. |
| 430 */ | 430 */ |
| 431 function ScriptLineCount() { | 431 function ScriptLineCount() { |
| 432 // Return number of source lines. | 432 // Return number of source lines. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 this.end = end; | 511 this.end = end; |
| 512 } | 512 } |
| 513 | 513 |
| 514 | 514 |
| 515 /** | 515 /** |
| 516 * Get the source text for a SourceLocation | 516 * Get the source text for a SourceLocation |
| 517 * @return {String} | 517 * @return {String} |
| 518 * Source text for this location. | 518 * Source text for this location. |
| 519 */ | 519 */ |
| 520 function SourceLocationSourceText() { | 520 function SourceLocationSourceText() { |
| 521 return %_CallFunction(this.script.source, | 521 return %_Call(StringSubstring, this.script.source, this.start, this.end); |
| 522 this.start, | |
| 523 this.end, | |
| 524 StringSubstring); | |
| 525 } | 522 } |
| 526 | 523 |
| 527 | 524 |
| 528 utils.SetUpLockedPrototype(SourceLocation, | 525 utils.SetUpLockedPrototype(SourceLocation, |
| 529 ["script", "position", "line", "column", "start", "end"], | 526 ["script", "position", "line", "column", "start", "end"], |
| 530 ["sourceText", SourceLocationSourceText] | 527 ["sourceText", SourceLocationSourceText] |
| 531 ); | 528 ); |
| 532 | 529 |
| 533 | 530 |
| 534 /** | 531 /** |
| (...skipping 21 matching lines...) Expand all Loading... |
| 556 this.from_position = from_position; | 553 this.from_position = from_position; |
| 557 this.to_position = to_position; | 554 this.to_position = to_position; |
| 558 } | 555 } |
| 559 | 556 |
| 560 /** | 557 /** |
| 561 * Get the source text for a SourceSlice | 558 * Get the source text for a SourceSlice |
| 562 * @return {String} Source text for this slice. The last line will include | 559 * @return {String} Source text for this slice. The last line will include |
| 563 * the line terminating characters (if any) | 560 * the line terminating characters (if any) |
| 564 */ | 561 */ |
| 565 function SourceSliceSourceText() { | 562 function SourceSliceSourceText() { |
| 566 return %_CallFunction(this.script.source, | 563 return %_Call(StringSubstring, |
| 567 this.from_position, | 564 this.script.source, |
| 568 this.to_position, | 565 this.from_position, |
| 569 StringSubstring); | 566 this.to_position); |
| 570 } | 567 } |
| 571 | 568 |
| 572 utils.SetUpLockedPrototype(SourceSlice, | 569 utils.SetUpLockedPrototype(SourceSlice, |
| 573 ["script", "from_line", "to_line", "from_position", "to_position"], | 570 ["script", "from_line", "to_line", "from_position", "to_position"], |
| 574 ["sourceText", SourceSliceSourceText] | 571 ["sourceText", SourceSliceSourceText] |
| 575 ); | 572 ); |
| 576 | 573 |
| 577 | 574 |
| 578 function GetStackTraceLine(recv, fun, pos, isGlobal) { | 575 function GetStackTraceLine(recv, fun, pos, isGlobal) { |
| 579 return new CallSite(recv, fun, pos, false).toString(); | 576 return new CallSite(recv, fun, pos, false).toString(); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 | 684 |
| 688 var line = ""; | 685 var line = ""; |
| 689 var functionName = this.getFunctionName(); | 686 var functionName = this.getFunctionName(); |
| 690 var addSuffix = true; | 687 var addSuffix = true; |
| 691 var isConstructor = this.isConstructor(); | 688 var isConstructor = this.isConstructor(); |
| 692 var isMethodCall = !(this.isToplevel() || isConstructor); | 689 var isMethodCall = !(this.isToplevel() || isConstructor); |
| 693 if (isMethodCall) { | 690 if (isMethodCall) { |
| 694 var typeName = GetTypeName(GET_PRIVATE(this, callSiteReceiverSymbol), true); | 691 var typeName = GetTypeName(GET_PRIVATE(this, callSiteReceiverSymbol), true); |
| 695 var methodName = this.getMethodName(); | 692 var methodName = this.getMethodName(); |
| 696 if (functionName) { | 693 if (functionName) { |
| 697 if (typeName && | 694 if (typeName && %_Call(StringIndexOf, functionName, typeName) != 0) { |
| 698 %_CallFunction(functionName, typeName, StringIndexOf) != 0) { | |
| 699 line += typeName + "."; | 695 line += typeName + "."; |
| 700 } | 696 } |
| 701 line += functionName; | 697 line += functionName; |
| 702 if (methodName && | 698 if (methodName && |
| 703 (%_CallFunction(functionName, "." + methodName, StringIndexOf) != | 699 (%_Call(StringIndexOf, functionName, "." + methodName) != |
| 704 functionName.length - methodName.length - 1)) { | 700 functionName.length - methodName.length - 1)) { |
| 705 line += " [as " + methodName + "]"; | 701 line += " [as " + methodName + "]"; |
| 706 } | 702 } |
| 707 } else { | 703 } else { |
| 708 line += typeName + "." + (methodName || "<anonymous>"); | 704 line += typeName + "." + (methodName || "<anonymous>"); |
| 709 } | 705 } |
| 710 } else if (isConstructor) { | 706 } else if (isConstructor) { |
| 711 line += "new " + (functionName || "<anonymous>"); | 707 line += "new " + (functionName || "<anonymous>"); |
| 712 } else if (functionName) { | 708 } else if (functionName) { |
| 713 line += functionName; | 709 line += functionName; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 } | 771 } |
| 776 } | 772 } |
| 777 } | 773 } |
| 778 | 774 |
| 779 return eval_origin; | 775 return eval_origin; |
| 780 } | 776 } |
| 781 | 777 |
| 782 | 778 |
| 783 function FormatErrorString(error) { | 779 function FormatErrorString(error) { |
| 784 try { | 780 try { |
| 785 return %_CallFunction(error, ErrorToString); | 781 return %_Call(ErrorToString, error); |
| 786 } catch (e) { | 782 } catch (e) { |
| 787 try { | 783 try { |
| 788 return "<error: " + e + ">"; | 784 return "<error: " + e + ">"; |
| 789 } catch (ee) { | 785 } catch (ee) { |
| 790 return "<error>"; | 786 return "<error>"; |
| 791 } | 787 } |
| 792 } | 788 } |
| 793 } | 789 } |
| 794 | 790 |
| 795 | 791 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 } catch (e) { | 837 } catch (e) { |
| 842 try { | 838 try { |
| 843 line = "<error: " + e + ">"; | 839 line = "<error: " + e + ">"; |
| 844 } catch (ee) { | 840 } catch (ee) { |
| 845 // Any code that reaches this point is seriously nasty! | 841 // Any code that reaches this point is seriously nasty! |
| 846 line = "<error>"; | 842 line = "<error>"; |
| 847 } | 843 } |
| 848 } | 844 } |
| 849 lines.push(" at " + line); | 845 lines.push(" at " + line); |
| 850 } | 846 } |
| 851 return %_CallFunction(lines, "\n", ArrayJoin); | 847 return %_Call(ArrayJoin, lines, "\n"); |
| 852 } | 848 } |
| 853 | 849 |
| 854 | 850 |
| 855 function GetTypeName(receiver, requireConstructor) { | 851 function GetTypeName(receiver, requireConstructor) { |
| 856 if (IS_NULL_OR_UNDEFINED(receiver)) return null; | 852 if (IS_NULL_OR_UNDEFINED(receiver)) return null; |
| 857 var constructor = receiver.constructor; | 853 var constructor = receiver.constructor; |
| 858 if (!constructor) { | 854 if (!constructor) { |
| 859 return requireConstructor ? null : | 855 return requireConstructor ? null : |
| 860 %_CallFunction(receiver, NoSideEffectsObjectToString); | 856 %_Call(NoSideEffectsObjectToString, receiver); |
| 861 } | 857 } |
| 862 var constructorName = constructor.name; | 858 var constructorName = constructor.name; |
| 863 if (!constructorName) { | 859 if (!constructorName) { |
| 864 return requireConstructor ? null : | 860 return requireConstructor ? null : |
| 865 %_CallFunction(receiver, NoSideEffectsObjectToString); | 861 %_Call(NoSideEffectsObjectToString, receiver); |
| 866 } | 862 } |
| 867 return constructorName; | 863 return constructorName; |
| 868 } | 864 } |
| 869 | 865 |
| 870 | 866 |
| 871 // Format the stack trace if not yet done, and return it. | 867 // Format the stack trace if not yet done, and return it. |
| 872 // Cache the formatted stack trace on the holder. | 868 // Cache the formatted stack trace on the holder. |
| 873 var StackTraceGetter = function() { | 869 var StackTraceGetter = function() { |
| 874 var formatted_stack_trace = UNDEFINED; | 870 var formatted_stack_trace = UNDEFINED; |
| 875 var holder = this; | 871 var holder = this; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 utils.Export(function(to) { | 1032 utils.Export(function(to) { |
| 1037 to.ErrorToString = ErrorToString; | 1033 to.ErrorToString = ErrorToString; |
| 1038 to.MakeError = MakeError; | 1034 to.MakeError = MakeError; |
| 1039 to.MakeRangeError = MakeRangeError; | 1035 to.MakeRangeError = MakeRangeError; |
| 1040 to.MakeSyntaxError = MakeSyntaxError; | 1036 to.MakeSyntaxError = MakeSyntaxError; |
| 1041 to.MakeTypeError = MakeTypeError; | 1037 to.MakeTypeError = MakeTypeError; |
| 1042 to.MakeURIError = MakeURIError; | 1038 to.MakeURIError = MakeURIError; |
| 1043 }); | 1039 }); |
| 1044 | 1040 |
| 1045 }); | 1041 }); |
| OLD | NEW |