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

Side by Side Diff: src/d8.js

Issue 9415010: Make built-ins strict mode conforming, and support a --use-strict flag. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed Yang's comments. Created 8 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/compiler.cc ('k') | src/date.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 2008 the V8 project authors. All rights reserved. 1 // Copyright 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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 "use strict";
29
28 String.prototype.startsWith = function (str) { 30 String.prototype.startsWith = function (str) {
29 if (str.length > this.length) { 31 if (str.length > this.length) {
30 return false; 32 return false;
31 } 33 }
32 return this.substr(0, str.length) == str; 34 return this.substr(0, str.length) == str;
33 }; 35 };
34 36
35 function log10(num) { 37 function log10(num) {
36 return Math.log(num)/Math.log(10); 38 return Math.log(num)/Math.log(10);
37 } 39 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 result.push(name); 71 result.push(name);
70 } 72 }
71 } 73 }
72 current = ToInspectableObject(current.__proto__); 74 current = ToInspectableObject(current.__proto__);
73 } 75 }
74 return result; 76 return result;
75 } 77 }
76 78
77 79
78 // Global object holding debugger related constants and state. 80 // Global object holding debugger related constants and state.
79 const Debug = {}; 81 var Debug = {};
80 82
81 83
82 // Debug events which can occour in the V8 JavaScript engine. These originate 84 // Debug events which can occour in the V8 JavaScript engine. These originate
83 // from the API include file v8-debug.h. 85 // from the API include file v8-debug.h.
84 Debug.DebugEvent = { Break: 1, 86 Debug.DebugEvent = { Break: 1,
85 Exception: 2, 87 Exception: 2,
86 NewFunction: 3, 88 NewFunction: 3,
87 BeforeCompile: 4, 89 BeforeCompile: 4,
88 AfterCompile: 5 }; 90 AfterCompile: 5 };
89 91
(...skipping 14 matching lines...) Expand all
104 // The different types of scopes matching constants runtime.cc. 106 // The different types of scopes matching constants runtime.cc.
105 Debug.ScopeType = { Global: 0, 107 Debug.ScopeType = { Global: 0,
106 Local: 1, 108 Local: 1,
107 With: 2, 109 With: 2,
108 Closure: 3, 110 Closure: 3,
109 Catch: 4, 111 Catch: 4,
110 Block: 5 }; 112 Block: 5 };
111 113
112 114
113 // Current debug state. 115 // Current debug state.
114 const kNoFrame = -1; 116 var kNoFrame = -1;
115 Debug.State = { 117 Debug.State = {
116 currentFrame: kNoFrame, 118 currentFrame: kNoFrame,
117 displaySourceStartLine: -1, 119 displaySourceStartLine: -1,
118 displaySourceEndLine: -1, 120 displaySourceEndLine: -1,
119 currentSourceLine: -1 121 currentSourceLine: -1
120 }; 122 };
121 var trace_compile = false; // Tracing all compile events? 123 var trace_compile = false; // Tracing all compile events?
122 var trace_debug_json = false; // Tracing all debug json packets? 124 var trace_debug_json = false; // Tracing all debug json packets?
123 var last_cmd_line = ''; 125 var last_cmd_line = '';
124 //var lol_is_enabled; // Set to true in d8.cc if LIVE_OBJECT_LIST is defined. 126 //var lol_is_enabled; // Set to true in d8.cc if LIVE_OBJECT_LIST is defined.
125 var lol_next_dump_index = 0; 127 var lol_next_dump_index = 0;
126 const kDefaultLolLinesToPrintAtATime = 10; 128 var kDefaultLolLinesToPrintAtATime = 10;
127 const kMaxLolLinesToPrintAtATime = 1000; 129 var kMaxLolLinesToPrintAtATime = 1000;
128 var repeat_cmd_line = ''; 130 var repeat_cmd_line = '';
129 var is_running = true; 131 var is_running = true;
130 132
131 // Copied from debug-delay.js. This is needed below: 133 // Copied from debug-delay.js. This is needed below:
132 function ScriptTypeFlag(type) { 134 function ScriptTypeFlag(type) {
133 return (1 << type); 135 return (1 << type);
134 } 136 }
135 137
136 138
137 // Process a debugger JSON message into a display text and a running status. 139 // Process a debugger JSON message into a display text and a running status.
(...skipping 2484 matching lines...) Expand 10 before | Expand all | Expand 10 after
2622 } 2624 }
2623 2625
2624 2626
2625 function NumberToJSON_(value) { 2627 function NumberToJSON_(value) {
2626 return String(value); 2628 return String(value);
2627 } 2629 }
2628 2630
2629 2631
2630 // Mapping of some control characters to avoid the \uXXXX syntax for most 2632 // Mapping of some control characters to avoid the \uXXXX syntax for most
2631 // commonly used control cahracters. 2633 // commonly used control cahracters.
2632 const ctrlCharMap_ = { 2634 var ctrlCharMap_ = {
2633 '\b': '\\b', 2635 '\b': '\\b',
2634 '\t': '\\t', 2636 '\t': '\\t',
2635 '\n': '\\n', 2637 '\n': '\\n',
2636 '\f': '\\f', 2638 '\f': '\\f',
2637 '\r': '\\r', 2639 '\r': '\\r',
2638 '"' : '\\"', 2640 '"' : '\\"',
2639 '\\': '\\\\' 2641 '\\': '\\\\'
2640 }; 2642 };
2641 2643
2642 2644
2643 // Regular expression testing for ", \ and control characters (0x00 - 0x1F). 2645 // Regular expression testing for ", \ and control characters (0x00 - 0x1F).
2644 const ctrlCharTest_ = new RegExp('["\\\\\x00-\x1F]'); 2646 var ctrlCharTest_ = new RegExp('["\\\\\x00-\x1F]');
2645 2647
2646 2648
2647 // Regular expression matching ", \ and control characters (0x00 - 0x1F) 2649 // Regular expression matching ", \ and control characters (0x00 - 0x1F)
2648 // globally. 2650 // globally.
2649 const ctrlCharMatch_ = new RegExp('["\\\\\x00-\x1F]', 'g'); 2651 var ctrlCharMatch_ = new RegExp('["\\\\\x00-\x1F]', 'g');
2650 2652
2651 2653
2652 /** 2654 /**
2653 * Convert a String to its JSON representation (see http://www.json.org/). To 2655 * Convert a String to its JSON representation (see http://www.json.org/). To
2654 * avoid depending on the String object this method calls the functions in 2656 * avoid depending on the String object this method calls the functions in
2655 * string.js directly and not through the value. 2657 * string.js directly and not through the value.
2656 * @param {String} value The String value to format as JSON 2658 * @param {String} value The String value to format as JSON
2657 * @return {string} JSON formatted String value 2659 * @return {string} JSON formatted String value
2658 */ 2660 */
2659 function StringToJSON_(value) { 2661 function StringToJSON_(value) {
(...skipping 21 matching lines...) Expand all
2681 2683
2682 2684
2683 /** 2685 /**
2684 * Convert a Date to ISO 8601 format. To avoid depending on the Date object 2686 * Convert a Date to ISO 8601 format. To avoid depending on the Date object
2685 * this method calls the functions in date.js directly and not through the 2687 * this method calls the functions in date.js directly and not through the
2686 * value. 2688 * value.
2687 * @param {Date} value The Date value to format as JSON 2689 * @param {Date} value The Date value to format as JSON
2688 * @return {string} JSON formatted Date value 2690 * @return {string} JSON formatted Date value
2689 */ 2691 */
2690 function DateToISO8601_(value) { 2692 function DateToISO8601_(value) {
2691 function f(n) { 2693 var f = function(n) {
2692 return n < 10 ? '0' + n : n; 2694 return n < 10 ? '0' + n : n;
2693 } 2695 };
2694 function g(n) { 2696 var g = function(n) {
2695 return n < 10 ? '00' + n : n < 100 ? '0' + n : n; 2697 return n < 10 ? '00' + n : n < 100 ? '0' + n : n;
2696 } 2698 };
2697 return builtins.GetUTCFullYearFrom(value) + '-' + 2699 return builtins.GetUTCFullYearFrom(value) + '-' +
2698 f(builtins.GetUTCMonthFrom(value) + 1) + '-' + 2700 f(builtins.GetUTCMonthFrom(value) + 1) + '-' +
2699 f(builtins.GetUTCDateFrom(value)) + 'T' + 2701 f(builtins.GetUTCDateFrom(value)) + 'T' +
2700 f(builtins.GetUTCHoursFrom(value)) + ':' + 2702 f(builtins.GetUTCHoursFrom(value)) + ':' +
2701 f(builtins.GetUTCMinutesFrom(value)) + ':' + 2703 f(builtins.GetUTCMinutesFrom(value)) + ':' +
2702 f(builtins.GetUTCSecondsFrom(value)) + '.' + 2704 f(builtins.GetUTCSecondsFrom(value)) + '.' +
2703 g(builtins.GetUTCMillisecondsFrom(value)) + 'Z'; 2705 g(builtins.GetUTCMillisecondsFrom(value)) + 'Z';
2704 } 2706 }
2705 2707
2706 2708
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
2801 json += NumberToJSON_(elem); 2803 json += NumberToJSON_(elem);
2802 } else if (typeof(elem) === 'string') { 2804 } else if (typeof(elem) === 'string') {
2803 json += StringToJSON_(elem); 2805 json += StringToJSON_(elem);
2804 } else { 2806 } else {
2805 json += elem; 2807 json += elem;
2806 } 2808 }
2807 } 2809 }
2808 json += ']'; 2810 json += ']';
2809 return json; 2811 return json;
2810 } 2812 }
OLDNEW
« no previous file with comments | « src/compiler.cc ('k') | src/date.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698