Example #1
0
/**
 * Add JS bindings
 */
void FSModule::loadGlobalJS( v8::Local<v8::ObjectTemplate> &global ) {
  // Create global fs object
  Handle<ObjectTemplate> fsTemplate = ObjectTemplate::New(getIsolate());
  
  fsTemplate->Set(v8::String::NewFromUtf8(getIsolate(), "existsSync"), v8::FunctionTemplate::New(getIsolate(), existsSync));
  fsTemplate->Set(v8::String::NewFromUtf8(getIsolate(), "readFileSync"), v8::FunctionTemplate::New(getIsolate(), readFileSync));
  fsTemplate->Set(v8::String::NewFromUtf8(getIsolate(), "statSync"), v8::FunctionTemplate::New(getIsolate(), statSync));
  
  // Expose global fs object
  global->Set(v8::String::NewFromUtf8(getIsolate(), "_fs"), fsTemplate);
}
bool JSInterIsolateCallManager::doOneWork()
{
  JSInterIsolateCall::Ptr pCall = dequeue();
  if (!pCall)
  {
    return false;
  }
  
  js_enter_scope();
  JSLocalObjectHandle pUserData = getIsolate()->wrapExternalPointer(pCall->getUserData());
  JSValueHandle request = getIsolate()->parseJSON(pCall->json());
  JSArgumentVector jsonArg;
  jsonArg.push_back(request);
  jsonArg.push_back(pUserData);
  //
  // Check if this is a callback notification
  //
  if (pCall->_cb) {
    (*pCall->_cb)->Call(getGlobal(), jsonArg.size(), jsonArg.data());
    pCall->setValue("{}");
    pCall->_cb->Dispose();
    delete pCall->_cb;
    pCall->_cb = 0;
    return true;
  }
  
  if (_handler.empty())
  {
    //
    // return true here so that the event loop knows we processed something
    //
    pCall->setValue("{error: 'No handler set'}");
    return true;
  }
  

  JSValueHandle result =  _handler.value()->Call(getGlobal(), jsonArg.size(), jsonArg.data());

  std::string value;
  if (!result.IsEmpty() && result->IsString())
  {
    value = js_handle_as_std_string(result);
  }
  pCall->setValue(value);
  return true;
}
Example #3
0
/**
 * Add JS bindings
 */
void BatchModule::loadGlobalJS( v8::Local<v8::ObjectTemplate> &global ) {
  // Create global batch object
  Handle<ObjectTemplate> batchTemplate = ObjectTemplate::New(getIsolate());
  
  batchTemplate->Set(v8::String::NewFromUtf8(getIsolate(), "create"), v8::FunctionTemplate::New(getIsolate(), create));
  batchTemplate->Set(v8::String::NewFromUtf8(getIsolate(), "destroy"), v8::FunctionTemplate::New(getIsolate(), destroy));
  batchTemplate->Set(v8::String::NewFromUtf8(getIsolate(), "draw"), v8::FunctionTemplate::New(getIsolate(), draw));
  
  batchTemplate->Set(v8::String::NewFromUtf8(getIsolate(), "createVert"), v8::FunctionTemplate::New(getIsolate(), createVert));
  batchTemplate->Set(v8::String::NewFromUtf8(getIsolate(), "destroyVert"), v8::FunctionTemplate::New(getIsolate(), destroyVert));
  batchTemplate->Set(v8::String::NewFromUtf8(getIsolate(), "drawVert"), v8::FunctionTemplate::New(getIsolate(), drawVert));
  batchTemplate->Set(v8::String::NewFromUtf8(getIsolate(), "colorVert"), v8::FunctionTemplate::New(getIsolate(), colorVert));
  batchTemplate->Set(v8::String::NewFromUtf8(getIsolate(), "vertexVert"), v8::FunctionTemplate::New(getIsolate(), vertexVert));
  
  // Expose global batch object
  global->Set(v8::String::NewFromUtf8(getIsolate(), "batch"), batchTemplate);
}
NATraceList
ElemDDLUdrIsolate::getDetailInfo() const
{
  NAString        detailText;
  NATraceList detailTextList;

  detailText = "isolate? ";
  detailText += YesNo(getIsolate());
  detailTextList.append(detailText);

  return detailTextList;

}
void JSInterIsolateCallManager::notify(const Request& request, void* userData, JSPersistentFunctionHandle* cb)
{
  bool delegateToSelf = getIsolate()->isThreadSelf();
  JSInterIsolateCall::Ptr pCall(new JSInterIsolateCall(request, 0, userData, cb));
  enqueue(pCall);
  if (delegateToSelf)
  {
    doOneWork();
  }
  else
  {
    getEventLoop()->wakeup();
  }
}
Example #6
0
/**
 * Add JS bindings
 */
void VBOModule::loadGlobalJS( v8::Local<v8::ObjectTemplate> &global ) {
  // Create global object
  Handle<ObjectTemplate> objTemplate = ObjectTemplate::New(getIsolate());
  
  objTemplate->Set(v8::String::NewFromUtf8(getIsolate(), "create"), v8::FunctionTemplate::New(getIsolate(), create));
  objTemplate->Set(v8::String::NewFromUtf8(getIsolate(), "destroy"), v8::FunctionTemplate::New(getIsolate(), destroy));
  objTemplate->Set(v8::String::NewFromUtf8(getIsolate(), "bind"), v8::FunctionTemplate::New(getIsolate(), bind));
  objTemplate->Set(v8::String::NewFromUtf8(getIsolate(), "unbind"), v8::FunctionTemplate::New(getIsolate(), unbind));
  
  
  // Expose global object
  global->Set(v8::String::NewFromUtf8(getIsolate(), "vbo"), objTemplate);
}
bool JSInterIsolateCallManager::execute(const Request& request, Result& result, uint32_t timeout, void* userData)
{
  bool delegateToSelf = getIsolate()->isThreadSelf();
  JSInterIsolateCall::Ptr pCall(new JSInterIsolateCall(request, timeout, userData));
  enqueue(pCall);

  if (delegateToSelf)
  {
    doOneWork();
  }
  else
  {
    getEventLoop()->wakeup();
  }
  
  if (!pCall->waitForResult())
  {
    return false;
  }
  result = pCall->getResult();
  return true;
}
Example #8
0
/**
 * Add JS bindings
 */
void ConsoleModule::loadGlobalJS( v8::Local<v8::ObjectTemplate> &global ) {
  global->Set(v8::String::NewFromUtf8(getIsolate(), "log"), v8::FunctionTemplate::New(getIsolate(), LogCallback));
}