11cb0ef41Sopenharmony_ci// Copyright 2014 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci(function(global) {
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci  var GetProperties = function(this_name, object) {
81cb0ef41Sopenharmony_ci    var result = {};
91cb0ef41Sopenharmony_ci    try {
101cb0ef41Sopenharmony_ci      var names = Object.getOwnPropertyNames(object);
111cb0ef41Sopenharmony_ci    } catch(e) {
121cb0ef41Sopenharmony_ci      return;
131cb0ef41Sopenharmony_ci    }
141cb0ef41Sopenharmony_ci    for (var i = 0; i < names.length; ++i) {
151cb0ef41Sopenharmony_ci      var name = names[i];
161cb0ef41Sopenharmony_ci      if (typeof object === "function") {
171cb0ef41Sopenharmony_ci        if (name === "length" ||
181cb0ef41Sopenharmony_ci            name === "name" ||
191cb0ef41Sopenharmony_ci            name === "arguments" ||
201cb0ef41Sopenharmony_ci            name === "caller" ||
211cb0ef41Sopenharmony_ci            name === "prototype") {
221cb0ef41Sopenharmony_ci          continue;
231cb0ef41Sopenharmony_ci        }
241cb0ef41Sopenharmony_ci      }
251cb0ef41Sopenharmony_ci      // Avoid endless recursion.
261cb0ef41Sopenharmony_ci      if (this_name === "prototype" && name === "constructor") continue;
271cb0ef41Sopenharmony_ci      // Avoid needless duplication.
281cb0ef41Sopenharmony_ci      if (this_name === "__PROTO__" && name === "constructor") continue;
291cb0ef41Sopenharmony_ci      // Could get this from the parent, but having it locally is easier.
301cb0ef41Sopenharmony_ci      var property = { "name": name };
311cb0ef41Sopenharmony_ci      try {
321cb0ef41Sopenharmony_ci        var value = object[name];
331cb0ef41Sopenharmony_ci      } catch(e) {
341cb0ef41Sopenharmony_ci        property.type = "getter";
351cb0ef41Sopenharmony_ci        result[name] = property;
361cb0ef41Sopenharmony_ci        continue;
371cb0ef41Sopenharmony_ci      }
381cb0ef41Sopenharmony_ci      var type = typeof value;
391cb0ef41Sopenharmony_ci      property.type = type;
401cb0ef41Sopenharmony_ci      if (type === "function") {
411cb0ef41Sopenharmony_ci        property.length = value.length;
421cb0ef41Sopenharmony_ci        property.prototype = GetProperties("prototype", value.prototype);
431cb0ef41Sopenharmony_ci      }
441cb0ef41Sopenharmony_ci      if (type === "string" || type === "number") {
451cb0ef41Sopenharmony_ci        property.value = value;
461cb0ef41Sopenharmony_ci      } else {
471cb0ef41Sopenharmony_ci        property.properties = GetProperties(name, value);
481cb0ef41Sopenharmony_ci      }
491cb0ef41Sopenharmony_ci      result[name] = property;
501cb0ef41Sopenharmony_ci    }
511cb0ef41Sopenharmony_ci    // Print the __proto__ if it's not the default Object prototype.
521cb0ef41Sopenharmony_ci    if (typeof object === "object" && object.__proto__ !== null &&
531cb0ef41Sopenharmony_ci        !object.__proto__.hasOwnProperty("__proto__")) {
541cb0ef41Sopenharmony_ci      result.__PROTO__ = GetProperties("__PROTO__", object.__proto__);
551cb0ef41Sopenharmony_ci    }
561cb0ef41Sopenharmony_ci    return result;
571cb0ef41Sopenharmony_ci  };
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci  var g = GetProperties("", global, "");
601cb0ef41Sopenharmony_ci  print(JSON.stringify(g, undefined, 2));
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_ci})(this);  // Must wrap in anonymous closure or it'll detect itself as builtin.
63