Is it obvious to anyone why the call to WebSocket::pfunc_on_open crashes at 
this line 
"   processOnOpen->Call(global, 1, args);"

extern Isolate* isolate;
extern Handle<Context> g_context;
extern Handle < ObjectTemplate > globalTemplate;
extern Persistent<Context> p_context;

v8::Persistent<v8::Function> WebSocket::pfunc_on_open;

void WebSocket::exposeWebSocket(Handle<ObjectTemplate> globalTemplate) {

   LOGD(LOG_TAG, "In exposeWebSocket");
    
    
 
globalTemplate->Set(String::NewFromUtf8(isolate,"WebSocket"),FunctionTemplate::New(isolate,WebSocketConstructor));

}

void WebSocketConstructor(const v8::FunctionCallbackInfo<Value> &args) {

    LOGD(LOG_TAG, "In WebSocketConstructor()");

     Locker lock(isolate);
     HandleScope scope(isolate);
         
     Handle<ObjectTemplate> websocket_templ= ObjectTemplate::New();
     websocket_templ->SetInternalFieldCount(1);
     websocket_templ->Set(String::NewFromUtf8(isolate,"send"), 
FunctionTemplate::New(isolate,WebSocket::exposed_method_send));
     websocket_templ->Set(String::NewFromUtf8(isolate,"close"), 
FunctionTemplate::New(isolate,WebSocket::exposed_method_close));

     // Set up properties as event handlers
     websocket_templ->SetAccessor(String::NewFromUtf8(isolate,"onopen"), 
AccessorGetterCallback(WebSocket::GetOnCallback), 
AccessorSetterCallback(WebSocket::SetOnOpen));
     websocket_templ->SetAccessor(String::NewFromUtf8(isolate,"onmessage"), 
AccessorGetterCallback(WebSocket::GetOnCallback), 
AccessorSetterCallback(WebSocket::SetOnMessage));
     websocket_templ->SetAccessor(String::NewFromUtf8(isolate,"onerror"), 
AccessorGetterCallback(WebSocket::GetOnCallback), 
AccessorSetterCallback(WebSocket::SetOnFail));
     websocket_templ->SetAccessor(String::NewFromUtf8(isolate,"onclose"), 
AccessorGetterCallback(WebSocket::GetOnCallback), 
AccessorSetterCallback(WebSocket::SetOnClose));
     
     Handle<Object> ws_instance;
     if (!args[0].IsEmpty() && args[0]->IsString()) {

            String::Utf8Value p1(args[0]->ToString());
            LOGD(LOG_TAG, "WebSocketConstructor() - URL = %s", *p1);
            WebSocket* wsObject = new WebSocket(*p1);
            ws_instance = websocket_templ->NewInstance();
             ws_instance->SetInternalField(0, v8::External::New(isolate, 
wsObject));
            args.GetReturnValue().Set(ws_instance);

         }

}


void WebSocket::callEventCallback(const std::string event, const 
std::string message) {

    LOGD(LOG_TAG, "callEventCallback() - event = %s, message = %s", 
event.c_str(), message.c_str());
    Locker lock(isolate);
    HandleScope scope(isolate);

    v8::Local<v8::Context> context = v8::Local<v8::Context>::New(isolate, 
p_context);

    Context::Scope context_scope(context);
    Handle < v8::Object > global = context->Global();

    Handle < Value > args[1];

    if (event.compare(event_onopen) == 0) {
        args[0] = v8::String::NewFromUtf8(isolate,message.c_str());
        v8::Local<v8::Function> processOnOpen = 
v8::Local<v8::Function>::New(isolate, WebSocket::pfunc_on_open);       
        processOnOpen->Call(global, 1, args);

}

void WebSocket::SetOnOpen(Local<String> prop, Local<Value> value, const 
v8::PropertyCallbackInfo<void>& info) {

    Locker lock(isolate);
    HandleScope scope(isolate);
    String::Utf8Value str(prop);
    LOGD(LOG_TAG, "SetOnOpen(): property = %s", *str);

    Handle < Object > self = info.Holder();
    Handle < External > wrap = Handle < External > 
::Cast(self->GetInternalField(0));

    void* ptr = wrap->Value();

    WebSocket* ws = static_cast<WebSocket*>(ptr);

    if (value->IsFunction()) {

        // Store a persistent function handle in the callback map
        Handle<Function> callback = Handle<Function>::Cast(value);
        ws->pfunc_on_open.Reset(isolate, callback);
  }

}




-- 
-- 
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