title: How to iterate through all properties/functions of a global object(library) in v8?
body: <p>Google apps script provides a <a href="https://developers.google.com/apps-script/guides/libraries?hl=en" rel="nofollow noreferrer">library feature</a>, where if you include the project key, a library is added as global object. I'm looking to iterate all functions of a added library. This used to be possible in <a href="/questions/tagged/rhino" class="post-tag" title="show questions tagged &#39;rhino&#39;" rel="tag">rhino</a> engine with a <code>for...in</code> loop. But I'm unable to iterate through any of the properties of to a library in <a href="/questions/tagged/v8" class="post-tag" title="show questions tagged &#39;v8&#39;" rel="tag">v8</a> engine.</p>
  <p>The <a href="https://developers.google.com/apps-script/guides/v8-runtime/migration?hl=en#adjust_handling_of_instanceof_in_libraries" rel="nofollow noreferrer">documentation</a> says</p>
  <blockquote>
  <p>In the V8 runtime, a project and its libraries are run in different execution contexts and hence have different globals and prototype chains.</p>
  </blockquote>
  <p>Can anyone explain how this object is created or how to access all it's properties?</p>
  <h3>Project A:</h3>
  <pre><code>function testLib(prop = 'main') {
    const isEnumerable = MyLibrary.propertyIsEnumerable(prop);
    const isOwnProperty = MyLibrary.hasOwnProperty(prop);
    console.info({ isEnumerable, isOwnProperty }); // { isEnumerable: false, isOwnProperty: true }
    console.info(prop in MyLibrary);//true
    for (const property in MyLibrary) {
      //loop doesn't start
      console.info(property);
    }
    console.info(Object.getOwnPropertyDescriptor(MyLibrary, prop)); //logs expected  data:
    /*{ value: [Function: main],
    writable: true,
    enumerable: false,
    configurable: true }*/
    console.log(Object.getOwnPropertyDescriptors(MyLibrary)); //actual: {} Expected: array of all functions including `main`
    MyLibrary.a = 1;
    console.log(Object.getOwnPropertyDescriptors(MyLibrary)); //actual: {a:1} Expected: array of all functions including `main`
  }
  
  function testPropDescriptors() {
    const obj = { prop1: 1, b: 2 };
    console.log(Object.getOwnPropertyDescriptors(obj)); //logs expected data
    /*{prop1: { value: 1, writable: true, enumerable: true, configurable: true },
    b: { value: 2, writable: true, enumerable: true, configurable: true } }*/
  }
  </code></pre>
  <h3>MyLibrary(Project B):</h3>
  <pre><code>function main(){}
  function onEdit(){}
  </code></pre>
  <p>To reproduce,</p>
  <ul>
  <li>Create a new project by <a href="https://script.new" rel="nofollow noreferrer">clicking here</a> - say, Project A</li>
  <li><a href="https://script.new" rel="nofollow noreferrer">Create a another script project</a>(say Project B):
  <ul>
  <li>add a function named <code>main</code> in Project B and</li>
  <li><a href="https://developers.google.com/apps-script/concepts/deployments?hl=en#create_a_versioned_deployment" rel="nofollow noreferrer">Deploy it</a> by clicking deploy in top right.</li>
  <li><a href="https://developers.google.com/apps-script/guides/libraries?hl=en#add_a_library_to_your_script_project" rel="nofollow noreferrer">add it's key</a> in project A and name it <code>MyLibrary</code>.</li>
  </ul>
  </li>
  <li>Copy paste the above script in Project A, select <code>testLib</code> function and click run</li>
  </ul>