After upgrading to a newer version of V8 the constructorFunctionHandler I 
set with SetCallAsFunctionHandler does not seem to be working. When I try 
to execute the code below it produces this error:

TypeError: RemoteRequest is not a constructor

This sample code is unstructured and ugly, but it will reproduce the error.
It worked properly in past versions v8.
Thanks for the help.

Mike

-------------------
#include <v8.h>
using namespace v8;
#include "include/libplatform/libplatform.h"

Eternal<ObjectTemplate>* pRemoteRequestObjectTemplateEnternal;

class RJSRemoteRequest
{
   public:
   RJSRemoteRequest(){};
   ~RJSRemoteRequest(){};

   static void constructorFunctionHandler(const 
FunctionCallbackInfo<Value>& args)
   {
      Local<ObjectTemplate> tmplRmtRequest;
      if(pRemoteRequestObjectTemplateEnternal && 
!pRemoteRequestObjectTemplateEnternal->IsEmpty())
      {
         tmplRmtRequest = 
pRemoteRequestObjectTemplateEnternal->Get(args.GetIsolate());
         //Now make an real RemoteRequest C++ object and pass it.
         RJSRemoteRequest* pRemoteRequest = new RJSRemoteRequest();
         Local<Object> localObj = tmplRmtRequest->NewInstance();
         localObj->SetInternalField(0, External::New(args.GetIsolate(), 
pRemoteRequest));
         Persistent<Object> obj(args.GetIsolate(), localObj);
         obj.SetWeak<RJSRemoteRequest>(pRemoteRequest, 
RJSRemoteRequest::JSRemoteRequest_DestructorCallback, 
WeakCallbackType::kFinalizer);
         args.GetReturnValue().Set(obj);
         return;
      }
      args.GetReturnValue().SetNull();
   };
   static void JSRemoteRequest_DestructorCallback(const 
WeakCallbackInfo<RJSRemoteRequest>& oValue)
   {
      delete oValue.GetParameter();
   };

   static void JSRemoteRequest_execute(const FunctionCallbackInfo<Value>& 
args)
   {
      args.GetReturnValue().Set(v8::True(args.GetIsolate()));
      return;
   }
};

int main()
{
   std::string sTestScript("\"use strict\";\nvar rmtRequest = new 
RemoteRequest();\nrmtRequest.execute();");
   
   v8::Platform* pPlatform = platform::CreateDefaultPlatform();
   V8::InitializePlatform(pPlatform);
   V8::Initialize();

   Isolate::CreateParams params;
   params.array_buffer_allocator = 
v8::ArrayBuffer::Allocator::NewDefaultAllocator();
   v8::Isolate* pIsolate = v8::Isolate::New(params);

   v8::Isolate::Scope oIsolateLock(pIsolate); //Automatically handles 
Enter() and Leave() of the Isolate for us.
   v8::HandleScope IsolateScope(pIsolate);
   
   //Create an object template where our users can embed their own objects 
and such.
   //They are then baked into the global when the context is created.
   Handle<ObjectTemplate> oObjTemplate = ObjectTemplate::New(pIsolate);

   void* pPrivateData = new unsigned long[10]; //Make up some privates for 
tester.
   pRemoteRequestObjectTemplateEnternal = new Eternal<ObjectTemplate>;
   Local<ObjectTemplate> tmplRmtRequest;
   tmplRmtRequest = ObjectTemplate::New(pIsolate);
   tmplRmtRequest->SetInternalFieldCount(2);
  
 
tmplRmtRequest->SetCallAsFunctionHandler(RJSRemoteRequest::constructorFunctionHandler,
 
External::New(pIsolate, reinterpret_cast<void *>(pPrivateData)));
   tmplRmtRequest->Set(String::NewFromUtf8(pIsolate, "execute"), 
FunctionTemplate::New(pIsolate, RJSRemoteRequest::JSRemoteRequest_execute));
   pRemoteRequestObjectTemplateEnternal->Set(pIsolate, tmplRmtRequest);
   oObjTemplate->Set(v8::String::NewFromUtf8(pIsolate, "RemoteRequest"), 
tmplRmtRequest, ReadOnly);

   Local<Context> oContext = Context::New(pIsolate, NULL, oObjTemplate);
   Context::Scope context_scope(oContext);

   TryCatch trycatch(pIsolate);
   MaybeLocal<String> sScript = v8::String::NewFromUtf8(pIsolate, 
sTestScript.c_str(), v8::NewStringType::kNormal, (int)sTestScript.size());
   v8::Local<v8::String> sLocalScriptText;
   sScript.ToLocal(&sLocalScriptText);
   v8::ScriptCompiler::Source source(sLocalScriptText);
   MaybeLocal<UnboundScript> oMaybeScript = 
v8::ScriptCompiler::CompileUnboundScript(pIsolate, &source, 
v8::ScriptCompiler::kNoCompileOptions);
   Local<UnboundScript> oScript;
   oMaybeScript.ToLocal(&oScript);
   Local<Script> oLocalScript = oScript->BindToCurrentContext();
   Local<Value> oReturnVal;

   //Report any pending exception if hasn't been done already.
   if(!oLocalScript->Run(oContext).ToLocal(&oReturnVal))
   {
      Local<Value> exception = trycatch.Exception();
      Handle<Message> message = trycatch.Message();
      String::Utf8Value exception_str(pIsolate, exception);
      int linenum = 0;
      message->GetLineNumber(oContext).To(&linenum);
      Local<String> localSourceLine;
      message->GetSourceLine(oContext).ToLocal(&localSourceLine);
      v8::String::Utf8Value sourceLine(pIsolate, localSourceLine);
      Local<String> localScriptName;
      
message->GetScriptResourceName()->ToString(oContext).ToLocal(&localScriptName);
      v8::String::Utf8Value scriptName(pIsolate, localScriptName);
      printf("Script error on Line %d\nError: %s\nLine Source: %s", 
linenum, (*exception_str), (*sourceLine));
   }

   V8::Dispose();
   V8::ShutdownPlatform();
   delete pPlatform;
}

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

Reply via email to