Reviewers: Yang,

Description:
Fix d8 object printing (symbols, accessors)

R=yang...@chromium.org
BUG=

Please review this at https://codereview.chromium.org/388243002/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+13, -6 lines):
  M src/d8.js


Index: src/d8.js
diff --git a/src/d8.js b/src/d8.js
index 10546c289f02e530a77c468949ed878e90e42c6a..1e64b3c50dfd38f8318bcf7f233f570665c912c4 100644
--- a/src/d8.js
+++ b/src/d8.js
@@ -1980,7 +1980,7 @@ function Stringify(x, depth) {
     case "string":
       return "\"" + x.toString() + "\"";
     case "symbol":
-      return "Symbol(" + (x.name ? Stringify(x.name, depth) : "") + ")"
+      return x.toString();
     case "object":
       if (IS_NULL(x)) return "null";
       if (x.constructor && x.constructor.name === "Array") {
@@ -1996,18 +1996,25 @@ function Stringify(x, depth) {
         if (string && string !== "[object Object]") return string;
       } catch(e) {}
       var props = [];
-      for (var name in x) {
+      var names = Object.getOwnPropertyNames(x);
+      if (Object.getOwnPropertySymbols) {
+        // FLAG_harmony_symbols is turned on.
+        names = names.concat(Object.getOwnPropertySymbols(x));
+      }
+      for (var i in names) {
+        var name = names[i];
         var desc = Object.getOwnPropertyDescriptor(x, name);
         if (IS_UNDEFINED(desc)) continue;
+        if (IS_SYMBOL(name)) name = "[" + Stringify(name) + "]";
         if ("value" in desc) {
           props.push(name + ": " + Stringify(desc.value, depth - 1));
         }
-        if ("get" in desc) {
-          var getter = desc.get.toString();
+        if (desc.get) {
+          var getter = Stringify(desc.get);
           props.push("get " + name + getter.slice(getter.indexOf('(')));
         }
-        if ("set" in desc) {
-          var setter = desc.set.toString();
+        if (desc.set) {
+          var setter = Stringify(desc.set);
           props.push("set " + name + setter.slice(setter.indexOf('(')));
         }
       }


--
--
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to