title: V8 Interceptors code not working
body: <p>I started learning V8, but i have been stuck at implementing Interceptors. I am having run time error in this code.</p>
  
  <pre><code>#include "..\v8\\v8.h"
  #include "..\common\common.h"
  #include &lt;iostream&gt;
  #include "JsPoint.h"
  #include "GlobalVar.h"
  
  int main(int argc, char *argv[]) {
      if( argc != 2 ) {
          std::cout &lt;&lt; "Usage: " &lt;&lt; argv[0] &lt;&lt; " &lt; js file name &gt; \n";
          return 1;
      }
  
      using namespace v8;
      v8::Locker locker;
      v8::HandleScope scope;
      v8::Handle&lt;ObjectTemplate&gt; globalTemplate = v8::ObjectTemplate::New();
      Local&lt;FunctionTemplate&gt; pointTemplate;
      Local&lt;ObjectTemplate&gt; instanceTemplate;
  
      // ----------- Accessor -------------------------------------------------------------------------------
      pointTemplate = FunctionTemplate::New(PointConstructor);
      pointTemplate-&gt;SetClassName(String::New("Point"));
      instanceTemplate = pointTemplate-&gt;InstanceTemplate();
      instanceTemplate-&gt;SetInternalFieldCount(1);
      instanceTemplate-&gt;SetAccessor(String::New("x"), AccessorGetter(PointGetX), AccessorSetter(PointSetX));
      instanceTemplate-&gt;SetAccessor(String::New("y"), AccessorGetter(PointGetY), AccessorSetter(PointSetY));
      // --------------end Accessor -------------------------------------------------------------------------
  
      // In accessor we know what is the name after . like .x and .y
      // but when you do not, use interceptors.
      // ----------- Interceptor ----------------------------------------------------------------------------
      Handle&lt;ObjectTemplate&gt; globalVarTemplate = ObjectTemplate::New();
      //globalVarTemplate-&gt;NewInstance();
      globalVarTemplate-&gt;SetInternalFieldCount(1);
      globalVarTemplate-&gt;SetNamedPropertyHandler(GetGlobalVar, SetGlobalVar);
      auto it = Persistent&lt;ObjectTemplate&gt;::New(globalVarTemplate);
      Handle&lt;ObjectTemplate&gt; hit = it;
      Handle&lt;Object&gt; gv_instance = hit-&gt;NewInstance();   // **Failing HERE !!!**
      Handle&lt;External&gt; gv_to_set = External::New(MyGlobalVar::getInstance());
      gv_instance-&gt;SetInternalField(0, gv_to_set);
      //-------------- end Interceptor ----------------------------------------------------------------------
  
      globalTemplate-&gt;Set(String::New("Global"), gv_instance, ReadOnly);
      globalTemplate-&gt;Set(String::New("Point"), pointTemplate, ReadOnly);
  
      Persistent&lt;v8::Context&gt; context = v8::Context::New(NULL, globalTemplate);
      Context::Scope cscope = Context::Scope(context);
  
      executeScript( argv[1], context );
  
      context.Dispose();
      v8::V8::Dispose();
      return 0;
  }
  </code></pre>
  
  <p>when i comment out the interceptor part, it works perfectly. It fails at <code>NewInstance()</code> call of Interceptor. Since i am new to V8, if you find any other mistake, point them out too.</p>
  
  <p>Thanks.</p>