1// Copyright 2014 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5(function(global) {
6
7  var GetProperties = function(this_name, object) {
8    var result = {};
9    try {
10      var names = Object.getOwnPropertyNames(object);
11    } catch(e) {
12      return;
13    }
14    for (var i = 0; i < names.length; ++i) {
15      var name = names[i];
16      if (typeof object === "function") {
17        if (name === "length" ||
18            name === "name" ||
19            name === "arguments" ||
20            name === "caller" ||
21            name === "prototype") {
22          continue;
23        }
24      }
25      // Avoid endless recursion.
26      if (this_name === "prototype" && name === "constructor") continue;
27      // Could get this from the parent, but having it locally is easier.
28      var property = { "name": name };
29      try {
30        var value = object[name];
31      } catch(e) {
32        property.type = "getter";
33        result[name] = property;
34        continue;
35      }
36      var type = typeof value;
37      property.type = type;
38      if (type === "function") {
39        property.length = value.length;
40        property.prototype = GetProperties("prototype", value.prototype);
41      }
42      property.properties = GetProperties(name, value);
43      result[name] = property;
44    }
45    return result;
46  };
47
48  var g = GetProperties("", global, "");
49  print(JSON.stringify(g, undefined, 2));
50
51})(this);  // Must wrap in anonymous closure or it'll detect itself as builtin.
52