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

Side by Side Diff: src/d8.js

Issue 8701006: Clean up JavaScript files to better follow coding standard. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years 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
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 String.prototype.startsWith = function (str) { 28 String.prototype.startsWith = function (str) {
29 if (str.length > this.length) 29 if (str.length > this.length) {
30 return false; 30 return false;
31 }
31 return this.substr(0, str.length) == str; 32 return this.substr(0, str.length) == str;
32 } 33 }
33 34
34 function log10(num) { 35 function log10(num) {
35 return Math.log(num)/Math.log(10); 36 return Math.log(num)/Math.log(10);
36 } 37 }
37 38
38 function ToInspectableObject(obj) { 39 function ToInspectableObject(obj) {
39 if (!obj && typeof obj === 'object') { 40 if (!obj && typeof obj === 'object') {
40 return void 0; 41 return void 0;
41 } else { 42 } else {
42 return Object(obj); 43 return Object(obj);
43 } 44 }
44 } 45 }
45 46
46 function GetCompletions(global, last, full) { 47 function GetCompletions(global, last, full) {
47 var full_tokens = full.split(); 48 var full_tokens = full.split();
48 full = full_tokens.pop(); 49 full = full_tokens.pop();
49 var parts = full.split('.'); 50 var parts = full.split('.');
50 parts.pop(); 51 parts.pop();
51 var current = global; 52 var current = global;
52 for (var i = 0; i < parts.length; i++) { 53 for (var i = 0; i < parts.length; i++) {
53 var part = parts[i]; 54 var part = parts[i];
54 var next = current[part]; 55 var next = current[part];
55 if (!next) 56 if (!next) {
56 return []; 57 return [];
58 }
57 current = next; 59 current = next;
58 } 60 }
59 var result = []; 61 var result = [];
60 current = ToInspectableObject(current); 62 current = ToInspectableObject(current);
61 while (typeof current !== 'undefined') { 63 while (typeof current !== 'undefined') {
62 var mirror = new $debug.ObjectMirror(current); 64 var mirror = new $debug.ObjectMirror(current);
63 var properties = mirror.properties(); 65 var properties = mirror.properties();
64 for (var i = 0; i < properties.length; i++) { 66 for (var i = 0; i < properties.length; i++) {
65 var name = properties[i].name(); 67 var name = properties[i].name();
66 if (typeof name === 'string' && name.startsWith(last)) 68 if (typeof name === 'string' && name.startsWith(last)) {
67 result.push(name); 69 result.push(name);
70 }
68 } 71 }
69 current = ToInspectableObject(current.__proto__); 72 current = ToInspectableObject(current.__proto__);
70 } 73 }
71 return result; 74 return result;
72 } 75 }
73 76
74 77
75 // Global object holding debugger related constants and state. 78 // Global object holding debugger related constants and state.
76 const Debug = {}; 79 const Debug = {};
77 80
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 is_running = response.running(); 146 is_running = response.running();
144 147
145 if (response.type() == 'event') { 148 if (response.type() == 'event') {
146 return DebugEventDetails(response); 149 return DebugEventDetails(response);
147 } else { 150 } else {
148 return DebugResponseDetails(response); 151 return DebugResponseDetails(response);
149 } 152 }
150 } 153 }
151 154
152 function DebugEventDetails(response) { 155 function DebugEventDetails(response) {
153 details = {text:'', running:false} 156 details = {text:'', running:false};
154 157
155 // Get the running state. 158 // Get the running state.
156 details.running = response.running(); 159 details.running = response.running();
157 160
158 var body = response.body(); 161 var body = response.body();
159 var result = ''; 162 var result = '';
160 switch (response.event()) { 163 switch (response.event()) {
161 case 'break': 164 case 'break':
162 if (body.breakpoints) { 165 if (body.breakpoints) {
163 result += 'breakpoint'; 166 result += 'breakpoint';
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 var json = '{'; 532 var json = '{';
530 json += '"seq":' + this.seq; 533 json += '"seq":' + this.seq;
531 json += ',"type":"' + this.type + '"'; 534 json += ',"type":"' + this.type + '"';
532 if (this.command) { 535 if (this.command) {
533 json += ',"command":' + StringToJSON_(this.command); 536 json += ',"command":' + StringToJSON_(this.command);
534 } 537 }
535 if (this.arguments) { 538 if (this.arguments) {
536 json += ',"arguments":'; 539 json += ',"arguments":';
537 // Encode the arguments part. 540 // Encode the arguments part.
538 if (this.arguments.toJSONProtocol) { 541 if (this.arguments.toJSONProtocol) {
539 json += this.arguments.toJSONProtocol() 542 json += this.arguments.toJSONProtocol();
540 } else { 543 } else {
541 json += SimpleObjectToJSON_(this.arguments); 544 json += SimpleObjectToJSON_(this.arguments);
542 } 545 }
543 } 546 }
544 json += '}'; 547 json += '}';
545 return json; 548 return json;
546 } 549 }
547 550
548 551
549 DebugRequest.prototype.createRequest = function(command) { 552 DebugRequest.prototype.createRequest = function(command) {
(...skipping 2181 matching lines...) Expand 10 before | Expand all | Expand 10 after
2731 if (typeof key == 'string') { 2734 if (typeof key == 'string') {
2732 var property_value = object[key]; 2735 var property_value = object[key];
2733 2736
2734 // Format the value based on its type. 2737 // Format the value based on its type.
2735 var property_value_json; 2738 var property_value_json;
2736 switch (typeof property_value) { 2739 switch (typeof property_value) {
2737 case 'object': 2740 case 'object':
2738 if (property_value === null) { 2741 if (property_value === null) {
2739 property_value_json = 'null'; 2742 property_value_json = 'null';
2740 } else if (typeof property_value.toJSONProtocol == 'function') { 2743 } else if (typeof property_value.toJSONProtocol == 'function') {
2741 property_value_json = property_value.toJSONProtocol(true) 2744 property_value_json = property_value.toJSONProtocol(true);
2742 } else if (property_value.constructor.name == 'Array'){ 2745 } else if (property_value.constructor.name == 'Array'){
2743 property_value_json = SimpleArrayToJSON_(property_value); 2746 property_value_json = SimpleArrayToJSON_(property_value);
2744 } else { 2747 } else {
2745 property_value_json = SimpleObjectToJSON_(property_value); 2748 property_value_json = SimpleObjectToJSON_(property_value);
2746 } 2749 }
2747 break; 2750 break;
2748 2751
2749 case 'boolean': 2752 case 'boolean':
2750 property_value_json = BooleanToJSON_(property_value); 2753 property_value_json = BooleanToJSON_(property_value);
2751 break; 2754 break;
(...skipping 30 matching lines...) Expand all
2782 */ 2785 */
2783 function SimpleArrayToJSON_(array) { 2786 function SimpleArrayToJSON_(array) {
2784 // Make JSON array representation. 2787 // Make JSON array representation.
2785 var json = '['; 2788 var json = '[';
2786 for (var i = 0; i < array.length; i++) { 2789 for (var i = 0; i < array.length; i++) {
2787 if (i != 0) { 2790 if (i != 0) {
2788 json += ','; 2791 json += ',';
2789 } 2792 }
2790 var elem = array[i]; 2793 var elem = array[i];
2791 if (elem.toJSONProtocol) { 2794 if (elem.toJSONProtocol) {
2792 json += elem.toJSONProtocol(true) 2795 json += elem.toJSONProtocol(true);
2793 } else if (typeof(elem) === 'object') { 2796 } else if (typeof(elem) === 'object') {
2794 json += SimpleObjectToJSON_(elem); 2797 json += SimpleObjectToJSON_(elem);
2795 } else if (typeof(elem) === 'boolean') { 2798 } else if (typeof(elem) === 'boolean') {
2796 json += BooleanToJSON_(elem); 2799 json += BooleanToJSON_(elem);
2797 } else if (typeof(elem) === 'number') { 2800 } else if (typeof(elem) === 'number') {
2798 json += NumberToJSON_(elem); 2801 json += NumberToJSON_(elem);
2799 } else if (typeof(elem) === 'string') { 2802 } else if (typeof(elem) === 'string') {
2800 json += StringToJSON_(elem); 2803 json += StringToJSON_(elem);
2801 } else { 2804 } else {
2802 json += elem; 2805 json += elem;
2803 } 2806 }
2804 } 2807 }
2805 json += ']'; 2808 json += ']';
2806 return json; 2809 return json;
2807 } 2810 }
OLDNEW
« no previous file with comments | « src/array.js ('k') | src/debug-debugger.js » ('j') | src/v8natives.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698