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

Side by Side Diff: src/d8.js

Issue 388243002: Fix d8 object printing (symbols, accessors) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 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 | « no previous file | no next file » | 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 // 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 "use strict"; 5 "use strict";
6 6
7 String.prototype.startsWith = function (str) { 7 String.prototype.startsWith = function (str) {
8 if (str.length > this.length) { 8 if (str.length > this.length) {
9 return false; 9 return false;
10 } 10 }
(...skipping 1962 matching lines...) Expand 10 before | Expand all | Expand 10 after
1973 switch (typeof x) { 1973 switch (typeof x) {
1974 case "undefined": 1974 case "undefined":
1975 return "undefined"; 1975 return "undefined";
1976 case "boolean": 1976 case "boolean":
1977 case "number": 1977 case "number":
1978 case "function": 1978 case "function":
1979 return x.toString(); 1979 return x.toString();
1980 case "string": 1980 case "string":
1981 return "\"" + x.toString() + "\""; 1981 return "\"" + x.toString() + "\"";
1982 case "symbol": 1982 case "symbol":
1983 return "Symbol(" + (x.name ? Stringify(x.name, depth) : "") + ")" 1983 return x.toString();
1984 case "object": 1984 case "object":
1985 if (IS_NULL(x)) return "null"; 1985 if (IS_NULL(x)) return "null";
1986 if (x.constructor && x.constructor.name === "Array") { 1986 if (x.constructor && x.constructor.name === "Array") {
1987 var elems = []; 1987 var elems = [];
1988 for (var i = 0; i < x.length; ++i) { 1988 for (var i = 0; i < x.length; ++i) {
1989 elems.push( 1989 elems.push(
1990 {}.hasOwnProperty.call(x, i) ? Stringify(x[i], depth - 1) : ""); 1990 {}.hasOwnProperty.call(x, i) ? Stringify(x[i], depth - 1) : "");
1991 } 1991 }
1992 return "[" + elems.join(", ") + "]"; 1992 return "[" + elems.join(", ") + "]";
1993 } 1993 }
1994 try { 1994 try {
1995 var string = String(x); 1995 var string = String(x);
1996 if (string && string !== "[object Object]") return string; 1996 if (string && string !== "[object Object]") return string;
1997 } catch(e) {} 1997 } catch(e) {}
1998 var props = []; 1998 var props = [];
1999 for (var name in x) { 1999 var names = Object.getOwnPropertyNames(x);
2000 if (Object.getOwnPropertySymbols) {
2001 // FLAG_harmony_symbols is turned on.
2002 names = names.concat(Object.getOwnPropertySymbols(x));
2003 }
2004 for (var i in names) {
2005 var name = names[i];
2000 var desc = Object.getOwnPropertyDescriptor(x, name); 2006 var desc = Object.getOwnPropertyDescriptor(x, name);
2001 if (IS_UNDEFINED(desc)) continue; 2007 if (IS_UNDEFINED(desc)) continue;
2008 if (IS_SYMBOL(name)) name = "[" + Stringify(name) + "]";
2002 if ("value" in desc) { 2009 if ("value" in desc) {
2003 props.push(name + ": " + Stringify(desc.value, depth - 1)); 2010 props.push(name + ": " + Stringify(desc.value, depth - 1));
2004 } 2011 }
2005 if ("get" in desc) { 2012 if (desc.get) {
2006 var getter = desc.get.toString(); 2013 var getter = Stringify(desc.get);
2007 props.push("get " + name + getter.slice(getter.indexOf('('))); 2014 props.push("get " + name + getter.slice(getter.indexOf('(')));
2008 } 2015 }
2009 if ("set" in desc) { 2016 if (desc.set) {
2010 var setter = desc.set.toString(); 2017 var setter = Stringify(desc.set);
2011 props.push("set " + name + setter.slice(setter.indexOf('('))); 2018 props.push("set " + name + setter.slice(setter.indexOf('(')));
2012 } 2019 }
2013 } 2020 }
2014 return "{" + props.join(", ") + "}"; 2021 return "{" + props.join(", ") + "}";
2015 default: 2022 default:
2016 return "[crazy non-standard shit]"; 2023 return "[crazy non-standard shit]";
2017 } 2024 }
2018 } 2025 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698