コード例 #1
0
void NotifySignal (uv_work_t *r) {
  v8::HandleScope scope;
  async_req_signal *req = reinterpret_cast<async_req_signal *>(r->data);
  v8::TryCatch try_catch;
  v8::Local<v8::Value> argv[3];
  // Create a new empty array.
  v8::Local<v8::Array> array = v8::Array::New(req->params.size ());
  // // Return an empty result if there was an error creating the array.
  //   if (array.IsEmpty())
  //     return Handle<Array>();
  std::vector <std::string>::iterator it;
  for (it = req->params.begin (); it != req->params.end (); it++)
    array->Set(0, v8::String::New(it->c_str ()));

  argv[0] = { v8::Local<v8::Value>::New(v8::String::New(req->quiddity_name.c_str ())) };
  argv[1] = { v8::Local<v8::Value>::New(v8::String::New(req->signal_name.c_str ())) };
  argv[2] = { v8::Local<v8::Value>::New(array)};
  
  
  if (!user_signal_cb.IsEmpty ())
    if (user_signal_cb->IsCallable ())
      user_signal_cb->Call(user_signal_cb, 3, argv);
  delete req;
  if (try_catch.HasCaught()) {
    node::FatalException(try_catch);
  }
}
コード例 #2
0
v8::Local<v8::Signature> configureTemplate(v8::Persistent<v8::FunctionTemplate> desc,
                                           const char *interfaceName,
                                           v8::Persistent<v8::FunctionTemplate> parentClass,
                                           int fieldCount,
                                           const BatchedAttribute* attributes, 
                                           size_t attributeCount,
                                           const BatchedCallback* callbacks,
                                           size_t callbackCount)
{
    desc->SetClassName(v8::String::New(interfaceName));
    v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate();
    instance->SetInternalFieldCount(fieldCount);
    if (!parentClass.IsEmpty())
        desc->Inherit(parentClass);
    if (attributeCount)
        batchConfigureAttributes(instance, desc->PrototypeTemplate(),
                                 attributes, attributeCount);
    v8::Local<v8::Signature> defaultSignature = v8::Signature::New(desc);
    if (callbackCount)
        batchConfigureCallbacks(desc->PrototypeTemplate(),
                                defaultSignature,
                                static_cast<v8::PropertyAttribute>(v8::DontDelete),
                                callbacks, callbackCount);
    return defaultSignature;
}
コード例 #3
0
void NotifyLog (uv_work_t *r) {
  v8::HandleScope scope;
  async_req_log *req = reinterpret_cast<async_req_log *>(r->data);
  v8::TryCatch try_catch;
  v8::Local<v8::Value> argv[] = { v8::Local<v8::Value>::New(v8::String::New(req->msg.c_str ())) };
  if (!user_log_cb.IsEmpty ())
    if (user_log_cb->IsCallable ())
      user_log_cb->Call(user_log_cb, 1, argv);
  delete req;
  if (try_catch.HasCaught()) {
    node::FatalException(try_catch);
  }
}
v8::Local<v8::Object> createV8ObjectForNPObject(NPObject* object, NPObject* root)
{
    static v8::Persistent<v8::FunctionTemplate> npObjectDesc;

    ASSERT(v8::Context::InContext());

    v8::Isolate* isolate = v8::Isolate::GetCurrent();

    // If this is a v8 object, just return it.
    V8NPObject* v8NPObject = npObjectToV8NPObject(object);
    if (v8NPObject)
        return v8::Local<v8::Object>::New(isolate, v8NPObject->v8Object);

    // If we've already wrapped this object, just return it.
    v8::Handle<v8::Object> wrapper = staticNPObjectMap().get(object);
    if (!wrapper.IsEmpty())
        return v8::Local<v8::Object>::New(isolate, wrapper);

    // FIXME: we should create a Wrapper type as a subclass of JSObject. It has two internal fields, field 0 is the wrapped
    // pointer, and field 1 is the type. There should be an api function that returns unused type id. The same Wrapper type
    // can be used by DOM bindings.
    if (npObjectDesc.IsEmpty()) {
        v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
        templ->InstanceTemplate()->SetInternalFieldCount(npObjectInternalFieldCount);
        templ->InstanceTemplate()->SetNamedPropertyHandler(npObjectNamedPropertyGetter, npObjectNamedPropertySetter, npObjectQueryProperty, 0, npObjectNamedPropertyEnumerator);
        templ->InstanceTemplate()->SetIndexedPropertyHandler(npObjectIndexedPropertyGetter, npObjectIndexedPropertySetter, 0, 0, npObjectIndexedPropertyEnumerator);
        templ->InstanceTemplate()->SetCallAsFunctionHandler(npObjectInvokeDefaultHandler);
        npObjectDesc.Reset(isolate, templ);
    }

    // FIXME: Move staticNPObjectMap() to DOMDataStore.
    // Use V8DOMWrapper::createWrapper() and
    // V8DOMWrapper::associateObjectWithWrapper()
    // to create a wrapper object.
    v8::Handle<v8::Function> v8Function = v8::Local<v8::FunctionTemplate>::New(isolate, npObjectDesc)->GetFunction();
    v8::Local<v8::Object> value = V8ObjectConstructor::newInstance(v8Function);
    if (value.IsEmpty())
        return value;

    V8DOMWrapper::setNativeInfo(value, npObjectTypeInfo(), object);

    // KJS retains the object as part of its wrapper (see Bindings::CInstance).
    _NPN_RetainObject(object);
    _NPN_RegisterObject(object, root);

    WrapperConfiguration configuration = buildWrapperConfiguration(object, WrapperConfiguration::Dependent);
    staticNPObjectMap().set(object, value, configuration);
    ASSERT(V8DOMWrapper::maybeDOMWrapper(value));
    return value;
}
コード例 #5
0
v8::Local<v8::Signature> V8DOMConfiguration::configureTemplate(v8::Persistent<v8::FunctionTemplate> functionDescriptor, const char* interfaceName, v8::Persistent<v8::FunctionTemplate> parentClass,
    size_t fieldCount, const BatchedAttribute* attributes, size_t attributeCount, const BatchedCallback* callbacks, size_t callbackCount, v8::Isolate* isolate)
{
    functionDescriptor->SetClassName(v8::String::NewSymbol(interfaceName));
    v8::Local<v8::ObjectTemplate> instance = functionDescriptor->InstanceTemplate();
    instance->SetInternalFieldCount(fieldCount);
    if (!parentClass.IsEmpty())
        functionDescriptor->Inherit(parentClass);
    if (attributeCount)
        batchConfigureAttributes(instance, functionDescriptor->PrototypeTemplate(), attributes, attributeCount, isolate);
    v8::Local<v8::Signature> defaultSignature = v8::Signature::New(functionDescriptor);
    if (callbackCount)
        batchConfigureCallbacks(functionDescriptor->PrototypeTemplate(), defaultSignature, static_cast<v8::PropertyAttribute>(v8::DontDelete), callbacks, callbackCount, isolate);
    return defaultSignature;
}
コード例 #6
0
ファイル: main.cpp プロジェクト: renbing/Canvas
void Java_com_woyouquan_Canvas_nativeDone( JNIEnv *env )
{
	zip_close(apkArchive);

	if( !jsMainLoop.IsEmpty() )
	{
		jsMainLoop.Dispose();
	}

	CTimer::getInstance()->clean();
	CV8Context::getInstance()->clean();

	curl_global_cleanup();

	LOG("canvas done");
}
コード例 #7
0
void NotifyProp (uv_work_t *r) {
  v8::HandleScope scope;
  async_req_prop *req = reinterpret_cast<async_req_prop *>(r->data);
  v8::TryCatch try_catch;
  v8::Local<v8::Value> argv[3];
  argv[0] = { v8::Local<v8::Value>::New(v8::String::New(req->quiddity_name.c_str ())) };
  argv[1] = { v8::Local<v8::Value>::New(v8::String::New(req->property_name.c_str ())) };
  argv[2] = { v8::Local<v8::Value>::New(v8::String::New(req->value.c_str ())) };
  if (!user_prop_cb.IsEmpty ())
    if (user_prop_cb->IsCallable ())
      user_prop_cb->Call(user_prop_cb, 3, argv);
  delete req;
  if (try_catch.HasCaught()) {
    node::FatalException(try_catch);
  }
}
コード例 #8
0
v8::Local<v8::Object> createV8ObjectForNPObject(NPObject* object, NPObject* root)
{
    static v8::Persistent<v8::FunctionTemplate> npObjectDesc;

    ASSERT(v8::Context::InContext());

    // If this is a v8 object, just return it.
    if (object->_class == npScriptObjectClass) {
        V8NPObject* v8NPObject = reinterpret_cast<V8NPObject*>(object);
        return v8::Local<v8::Object>::New(v8NPObject->v8Object);
    }

    // If we've already wrapped this object, just return it.
    if (staticNPObjectMap.contains(object))
        return v8::Local<v8::Object>::New(staticNPObjectMap.get(object));

    // FIXME: we should create a Wrapper type as a subclass of JSObject. It has two internal fields, field 0 is the wrapped
    // pointer, and field 1 is the type. There should be an api function that returns unused type id. The same Wrapper type
    // can be used by DOM bindings.
    if (npObjectDesc.IsEmpty()) {
        npObjectDesc = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New());
        npObjectDesc->InstanceTemplate()->SetInternalFieldCount(V8Custom::kNPObjectInternalFieldCount);
        npObjectDesc->InstanceTemplate()->SetNamedPropertyHandler(npObjectNamedPropertyGetter, npObjectNamedPropertySetter);
        npObjectDesc->InstanceTemplate()->SetIndexedPropertyHandler(npObjectIndexedPropertyGetter, npObjectIndexedPropertySetter);
        npObjectDesc->InstanceTemplate()->SetCallAsFunctionHandler(npObjectInvokeDefaultHandler);
    }

    v8::Handle<v8::Function> v8Function = npObjectDesc->GetFunction();
    v8::Local<v8::Object> value = SafeAllocation::newInstance(v8Function);

    // If we were unable to allocate the instance, we avoid wrapping and registering the NP object.
    if (value.IsEmpty())
        return value;

    wrapNPObject(value, object);

    // KJS retains the object as part of its wrapper (see Bindings::CInstance).
    _NPN_RetainObject(object);

    _NPN_RegisterObject(object, root);

    // Maintain a weak pointer for v8 so we can cleanup the object.
    v8::Persistent<v8::Object> weakRef = v8::Persistent<v8::Object>::New(value);
    staticNPObjectMap.set(object, weakRef);

    return value;
}
コード例 #9
0
v8::Persistent<v8::FunctionTemplate> V8HTMLAudioElementConstructor::GetTemplate()
{
    static v8::Persistent<v8::FunctionTemplate> cachedTemplate;
    if (!cachedTemplate.IsEmpty())
        return cachedTemplate;

    v8::HandleScope scope;
    v8::Local<v8::FunctionTemplate> result = v8::FunctionTemplate::New(USE_CALLBACK(HTMLAudioElementConstructor));

    v8::Local<v8::ObjectTemplate> instance = result->InstanceTemplate();
    instance->SetInternalFieldCount(V8Custom::kNodeMinimumInternalFieldCount);
    result->SetClassName(v8::String::New("HTMLAudioElement"));
    result->Inherit(V8DOMWrapper::getTemplate(V8ClassIndex::HTMLAUDIOELEMENT));

    cachedTemplate = v8::Persistent<v8::FunctionTemplate>::New(result);
    return cachedTemplate;
}
コード例 #10
0
ファイル: JSWrappers.cpp プロジェクト: nedbrek/osgearth
v8::Handle<v8::ObjectTemplate>
JSFeature::GetAttributesObjectTemplate()
{
    v8::HandleScope handle_scope;

    static v8::Persistent<v8::ObjectTemplate> attr_instance;

    if (attr_instance.IsEmpty())
    {
        attr_instance = v8::Persistent<v8::ObjectTemplate>::New(v8::ObjectTemplate::New());
        attr_instance->Set(v8::String::New(V8_OBJECT_TYPE_PROPERTY), v8::String::New("JSFeature_Attrs"));
        attr_instance->SetInternalFieldCount(1);
        attr_instance->SetNamedPropertyHandler(AttrPropertyCallback);
    }

    return attr_instance;
}
コード例 #11
0
v8::Persistent<v8::FunctionTemplate> V8TestNamedConstructorConstructor::GetTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
{
    static v8::Persistent<v8::FunctionTemplate> cachedTemplate;
    if (!cachedTemplate.IsEmpty())
        return cachedTemplate;

    v8::HandleScope scope;
    v8::Local<v8::FunctionTemplate> result = v8::FunctionTemplate::New(V8TestNamedConstructorConstructorCallback);

    v8::Local<v8::ObjectTemplate> instance = result->InstanceTemplate();
    instance->SetInternalFieldCount(V8TestNamedConstructor::internalFieldCount);
    result->SetClassName(v8::String::NewSymbol("TestNamedConstructor"));
    result->Inherit(V8TestNamedConstructor::GetTemplate(isolate, currentWorldType));

    cachedTemplate.Reset(isolate, result);
    return cachedTemplate;
}
コード例 #12
0
ファイル: JSWrappers.cpp プロジェクト: nedbrek/osgearth
v8::Handle<v8::ObjectTemplate>
JSFeature::GetObjectTemplate()
{
    v8::HandleScope handle_scope;

    static v8::Persistent<v8::ObjectTemplate> feat_instance;

    if (feat_instance.IsEmpty())
    {
        feat_instance = v8::Persistent<v8::ObjectTemplate>::New(v8::ObjectTemplate::New());
        feat_instance->Set(v8::String::New(V8_OBJECT_TYPE_PROPERTY), v8::String::New(GetObjectType().c_str()));
        feat_instance->SetInternalFieldCount(1);
        feat_instance->SetNamedPropertyHandler(PropertyCallback);
    }

    return feat_instance;
}
コード例 #13
0
v8::Persistent<v8::FunctionTemplate> V8HTMLAudioElementConstructor::GetTemplate()
{
    static v8::Persistent<v8::FunctionTemplate> cachedTemplate;
    if (!cachedTemplate.IsEmpty())
        return cachedTemplate;

    v8::HandleScope scope;
    v8::Local<v8::FunctionTemplate> result = v8::FunctionTemplate::New(v8HTMLAudioElementConstructorCallback);

    v8::Local<v8::ObjectTemplate> instance = result->InstanceTemplate();
    instance->SetInternalFieldCount(V8HTMLAudioElement::internalFieldCount);
    result->SetClassName(v8::String::New("HTMLAudioElement"));
    result->Inherit(V8HTMLAudioElement::GetTemplate());

    cachedTemplate = v8::Persistent<v8::FunctionTemplate>::New(result);
    return cachedTemplate;
}
コード例 #14
0
ファイル: main.cpp プロジェクト: renbing/Canvas
void Java_com_woyouquan_EAGLView_nativeRender( JNIEnv *env )
{
	glClear(GL_COLOR_BUFFER_BIT);
	
	v8::Locker locker;

	AsyncDownloadQueue::getInstance()->checkComplete();
	CWebSocket::mainLoop();

	if( !jsMainLoop.IsEmpty() )
	{
		CV8Context::getInstance()->callJSFunction(jsMainLoop, 0, 0);
	}

	CCanvas::getInstance()->getContext2D()->cleanDrawImage();

	//drawTest();
}
コード例 #15
0
ファイル: JSWrappers.cpp プロジェクト: nedbrek/osgearth
v8::Handle<v8::ObjectTemplate>
JSSymbologyGeometry::GetObjectTemplate()
{
    v8::HandleScope handle_scope;

    static v8::Persistent<v8::ObjectTemplate> template_instance;

    if (template_instance.IsEmpty())
    {
        template_instance = v8::Persistent<v8::ObjectTemplate>::New(v8::ObjectTemplate::New());
        template_instance->Set(v8::String::New(V8_OBJECT_TYPE_PROPERTY), v8::String::New(GetObjectType().c_str()));
        template_instance->SetInternalFieldCount(1);
        template_instance->SetNamedPropertyHandler(PropertyCallback);
        template_instance->SetIndexedPropertyHandler(IndexedPropertyCallback);
    }

    return template_instance;
}
コード例 #16
0
ファイル: JSWrappers.cpp プロジェクト: nedbrek/osgearth
v8::Handle<v8::ObjectTemplate>
JSGeoExtent::GetObjectTemplate()
{
    v8::HandleScope handle_scope;

    static v8::Persistent<v8::ObjectTemplate> template_instance;

    if (template_instance.IsEmpty())
    {
        template_instance = v8::Persistent<v8::ObjectTemplate>::New(v8::ObjectTemplate::New());
        template_instance->Set(v8::String::New(V8_OBJECT_TYPE_PROPERTY), v8::String::New(GetObjectType().c_str()));
        template_instance->SetInternalFieldCount(1);
        template_instance->SetNamedPropertyHandler(PropertyCallback);

        template_instance->Set(v8::String::New("contains"), v8::FunctionTemplate::New(ContainsCallback));
        template_instance->Set(v8::String::New("intersects"), v8::FunctionTemplate::New(IntersectsCallback));
    }

    return template_instance;
}
コード例 #17
0
ファイル: JSWrappers.cpp プロジェクト: nedbrek/osgearth
v8::Handle<v8::ObjectTemplate>
JSSession::GetObjectTemplate()
{
    v8::HandleScope handle_scope;

    static v8::Persistent<v8::ObjectTemplate> template_instance;

    if (template_instance.IsEmpty())
    {
        template_instance = v8::Persistent<v8::ObjectTemplate>::New(v8::ObjectTemplate::New());
        template_instance->Set(v8::String::New(V8_OBJECT_TYPE_PROPERTY), v8::String::New(GetObjectType().c_str()));
        template_instance->SetInternalFieldCount(1);
        template_instance->SetNamedPropertyHandler(PropertyCallback);

#if 0
        template_instance->Set(v8::String::New("resolveURI"), v8::FunctionTemplate::New(ResolveUriCallback));
#endif
    }

    return template_instance;
}
コード例 #18
0
v8::Local<v8::Function>
make_function(F f, CallPolicies const& p, Sig signature) {
    static v8::Persistent<v8::FunctionTemplate> proto_template;
    v8::Local<v8::FunctionTemplate> pt;
    if (proto_template.IsEmpty()) {
        pt = v8::FunctionTemplate::New(v8::Isolate::GetCurrent());
        pt->InstanceTemplate()->SetInternalFieldCount(1);
        proto_template.Reset(v8::Isolate::GetCurrent(), pt);
    } else {
        pt = v8::Local<v8::FunctionTemplate>::New(v8::Isolate::GetCurrent(), proto_template);
    }
    typedef typename detail::caller<F, CallPolicies, Sig> caller;
    v8::Local<v8::Value> c = caller::create(f, CallPolicies());
    v8::Local<v8::Function> function = v8::Function::New(v8::Isolate::GetCurrent(), caller::call, c);
    v8::Local<v8::Object> prototype = pt->GetFunction()->NewInstance();
    prototype->SetInternalField(0, c);
    v8::Local<v8::Value> original_proto = function->GetPrototype();
    function->SetPrototype(prototype);
    prototype->SetPrototype(original_proto);
    return function;
}
コード例 #19
0
ファイル: JSWrappers.cpp プロジェクト: nedbrek/osgearth
v8::Handle<v8::ObjectTemplate>
JSSpatialReference::GetObjectTemplate()
{
    v8::HandleScope handle_scope;

    static v8::Persistent<v8::ObjectTemplate> template_instance;

    if (template_instance.IsEmpty())
    {
        template_instance = v8::Persistent<v8::ObjectTemplate>::New(v8::ObjectTemplate::New());
        template_instance->Set(v8::String::New(V8_OBJECT_TYPE_PROPERTY), v8::String::New(GetObjectType().c_str()));
        template_instance->SetInternalFieldCount(1);
        template_instance->SetNamedPropertyHandler(PropertyCallback);

        template_instance->Set(v8::String::New("isEquivalentTo"), v8::FunctionTemplate::New(EquivalenceCallback));
        template_instance->Set(v8::String::New("createTangentPlaneSRS"), v8::FunctionTemplate::New(TangentPlaneCallback));
        //template_instance->Set(v8::String::New("createTransMercFromLongitude"), v8::FunctionTemplate::New(equivalenceCallback));
        //template_instance->Set(v8::String::New("createUTMFromLongitude"), v8::FunctionTemplate::New(equivalenceCallback));
    }

    return template_instance;
}
コード例 #20
0
ファイル: JSWrappers.cpp プロジェクト: nedbrek/osgearth
v8::Handle<v8::ObjectTemplate>
JSMapInfo::GetObjectTemplate()
{
    v8::HandleScope handle_scope;

    static v8::Persistent<v8::ObjectTemplate> template_instance;

    if (template_instance.IsEmpty())
    {
        template_instance = v8::Persistent<v8::ObjectTemplate>::New(v8::ObjectTemplate::New());
        template_instance->Set(v8::String::New(V8_OBJECT_TYPE_PROPERTY), v8::String::New(GetObjectType().c_str()));
        template_instance->SetInternalFieldCount(1);
        template_instance->SetNamedPropertyHandler(PropertyCallback);

#if 0
        template_instance->Set(v8::String::New("toMapPoint"), v8::FunctionTemplate::New(ToMapCallback));
        template_instance->Set(v8::String::New("mapPointToWorldPoint"), v8::FunctionTemplate::New(MapToWorldCallback));
        template_instance->Set(v8::String::New("worldPointToMapPoint"), v8::FunctionTemplate::New(WorldToMapCallback));
#endif
    }

    return template_instance;
}
コード例 #21
0
ファイル: JSWrappers.cpp プロジェクト: nedbrek/osgearth
v8::Handle<v8::ObjectTemplate>
JSFilterContext::GetObjectTemplate()
{
    v8::HandleScope handle_scope;

    static v8::Persistent<v8::ObjectTemplate> template_instance;

    if (template_instance.IsEmpty())
    {
        template_instance = v8::Persistent<v8::ObjectTemplate>::New(v8::ObjectTemplate::New());
        template_instance->Set(v8::String::New(V8_OBJECT_TYPE_PROPERTY), v8::String::New(GetObjectType().c_str()));
        template_instance->SetInternalFieldCount(1);
        template_instance->SetNamedPropertyHandler(PropertyCallback);

#if 0
        template_instance->Set(v8::String::New("toLocal"), v8::FunctionTemplate::New(ToLocalCallback));
        template_instance->Set(v8::String::New("toWorld"), v8::FunctionTemplate::New(ToWorldCallback));
        template_instance->Set(v8::String::New("toMap"), v8::FunctionTemplate::New(ToMapCallback));
        template_instance->Set(v8::String::New("fromMap"), v8::FunctionTemplate::New(FromMapCallback));
#endif
    }

    return template_instance;
}
コード例 #22
0
ファイル: v8u.hpp プロジェクト: jmendeth/parport.js
template <class T> inline void ClearPersistent(v8::Persistent<T>& handle) {
  if (handle.IsEmpty()) return;
  handle.Dispose();
  handle.Clear();
}