Example #1
0
void Shape::attributeSetValue(Local<String> name,
                              Local<Value> value,
                              const PropertyCallbackInfo<Value> &info)
{
  Local<Object> self = info.Holder();
  Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
  void *ptr = wrap->Value();
  map<string, int> *indexes = static_cast<map<string, int> *>(ptr);
  wrap = Local<External>::Cast(self->GetInternalField(1));
  ptr = wrap->Value();
  char **values = static_cast<char **>(ptr);

  String::Utf8Value utf8_name(name), utf8_value(value);
  string key = string(*utf8_name);

  map<string, int>::iterator iter = indexes->find(key);

  if (iter == indexes->end()) {
    ThrowException(String::New("Invalid value name."));
  }
  else
  {
    const int &index = (*iter).second;
    msFree(values[index]);
    values[index] = msStrdup(*utf8_value);
  }
}
void ObjectManager::Link(const Local<Object>& object, uint32_t javaObjectID, jclass clazz)
{
	auto isolate = Isolate::GetCurrent();

	DEBUG_WRITE("Linking js object: %d and java instance id: %d", object->GetIdentityHash(), javaObjectID);

	JEnv env;

	auto jsInstanceInfo = new JSInstanceInfo();
	jsInstanceInfo->JavaObjectID = javaObjectID;
	jsInstanceInfo->clazz = clazz;

	auto objectHandle = new Persistent<Object>(isolate, object);
	auto state = new ObjectWeakCallbackState(this, jsInstanceInfo, objectHandle);
	objectHandle->SetWeak(state, JSObjectWeakCallbackStatic);

	auto jsInfoIdx = static_cast<int>(MetadataNodeKeys::JsInfo);
	bool alreadyLinked = !object->GetInternalField(jsInfoIdx)->IsUndefined();
	//ASSERT_MESSAGE(alreadyLinked, "object should not have been linked before");

	auto jsInfo = External::New(isolate, jsInstanceInfo);
	object->SetInternalField(jsInfoIdx, jsInfo);

	idToObject.insert(make_pair(javaObjectID, objectHandle));
}
void ObjectManager::Link(const Local<Object>& object, uint32_t javaObjectID, jclass clazz)
{
	int internalFieldCound = NativeScriptExtension::GetInternalFieldCount(object);
	const int count = static_cast<int>(MetadataNodeKeys::END);
	if (internalFieldCound != count)
	{
		string errMsg("Trying to link invalid 'this' to a Java object");
		throw NativeScriptException(errMsg);
	}

	auto isolate = Isolate::GetCurrent();

	DEBUG_WRITE("Linking js object: %d and java instance id: %d", object->GetIdentityHash(), javaObjectID);

	auto jsInstanceInfo = new JSInstanceInfo();
	jsInstanceInfo->JavaObjectID = javaObjectID;
	jsInstanceInfo->clazz = clazz;

	auto objectHandle = new Persistent<Object>(isolate, object);
	auto state = new ObjectWeakCallbackState(this, jsInstanceInfo, objectHandle);
	objectHandle->SetWeak(state, JSObjectWeakCallbackStatic);

	auto jsInfoIdx = static_cast<int>(MetadataNodeKeys::JsInfo);
	bool alreadyLinked = !object->GetInternalField(jsInfoIdx)->IsUndefined();
	//TODO: fail if alreadyLinked is true?

	auto jsInfo = External::New(isolate, jsInstanceInfo);
	object->SetInternalField(jsInfoIdx, jsInfo);

	idToObject.insert(make_pair(javaObjectID, objectHandle));
}
Example #4
0
Handle<Array> jsWindow::WindowEnum( const AccessorInfo &info )
{
    HandleScope scope;

    Handle<Array> retval = Local<Array>::New(Array::New());

    Local<Object> self = info.This();
    Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
    void* ptr = wrap->Value();
    jsWindow* el = static_cast<jsWindow*>(ptr);

    map<string, int> prop_list;
    size_t i;
    for (i = 0; i < ro_props.size(); ++i) {
        prop_list[ro_props[i]] = 1;
    }
    jsPropertyMap::iterator it;
    for (it = el->props.begin(); it != el->props.end(); ++it) {
        prop_list[it->first] = 1;
    }
    map<string, int>::iterator ins;
    i = 0;
    for (ins = prop_list.begin(); ins != prop_list.end(); ++ins) {
        string val = ins->first;
        retval->Set(Number::New(i), String::New(val.c_str()));
        i++;
    }

    return scope.Close(retval);
}
Example #5
0
void *ScriptObject::extractHolder(const Arguments &args)
{
    HandleScope handleScope;

    // Extract first internal field from Argument's holder object

    Local<Object> holderObject = args.Holder();

    if (holderObject->InternalFieldCount() < 1)
        throw bit::Exception("No internal fields found in holder object");

    Local<Value> holderValue = holderObject->GetInternalField(0);

    if (holderValue.IsEmpty())
        throw bit::Exception("Internal field could not be extracted from object");

    if (!holderValue->IsExternal())
        throw bit::Exception("The first field of holder object is not an ExternalObject");

    // Extract void pointer

    void *holderPointer = External::Unwrap(holderValue);

    if (holderPointer == NULL)
        throw bit::Exception("Extracted pointer is null");

    return holderPointer;
}
Example #6
0
void SetPointY(Local<String> property, 
			   Local<Value> value,
			   const PropertyCallbackInfo<Value>& info)
{
	Local<Object> self = info.Holder();
	Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
	void* ptr = wrap->Value();
	static_cast<Point*>(ptr)->y_ = value->Int32Value();
}
Example #7
0
shared_ptr<Server> Server::GetInstance(Local<Context> context){
	sjs::logger::debug("Getting Instance");
	Local<Object> self = Local<Object>::Cast(context->Global()->Get(STRING2JS(context->GetIsolate(), "$sampjs")));
	Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
	void* ptr = wrap->Value();
	Server* server = static_cast<Server*>(ptr);
	sjs::logger::debug("Casting");
	return make_shared<Server>(*server);
}
static Handle<Value> GetLocationPort(Local<String> name, const AccessorInfo& info)
{
    Local<Object> self = info.This();
    Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
    void* ptr = wrap->Value();

    jsLocation* url = static_cast<jsLocation*>(ptr);
    return Int32::New(url->url.port);
}
Example #9
0
void GetPointY(Local<String> property,
						const PropertyCallbackInfo<Value>& info)
{
	Local<Object> self = info.Holder();
	Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
	void* ptr = wrap->Value();
	int value = static_cast<Point*>(ptr)->y_;
	info.GetReturnValue().Set(Number::New(value));
}
static void SetLocationPort(Local<String> name, Local<Value> val, const AccessorInfo& info)
{
    Local<Object> self = info.This();
    Local<Value> x = self->GetInternalField(0);
    Local<External> wrap = Local<External>::Cast(x);
    void* ptr = wrap->Value();

    jsLocation* url = static_cast<jsLocation*>(ptr);
    url->url.port = val->Int32Value();
}
static void SetLocationHost(Local<String> name, Local<Value> val, const AccessorInfo& info)
{
    Local<Object> self = info.This();
    Local<Value> x = self->GetInternalField(0);
    Local<External> wrap = Local<External>::Cast(x);
    void* ptr = wrap->Value();

    jsLocation* url = static_cast<jsLocation*>(ptr);
    url->url.assign_with_referer(value_to_string(val), &url->url);
}
static Handle<Value> GetLocationHash(Local<String> name, const AccessorInfo& info)
{
    Local<Object> self = info.This();
    Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
    void* ptr = wrap->Value();

    jsLocation* url = static_cast<jsLocation*>(ptr);
    string path = url->url.hashlink;
    return String::New(path.c_str());
}
Example #13
0
Handle<Value> getHeight(Local<String> property, const AccessorInfo &info) {
	Local<Object> self = info.Holder();
	Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
	void* ptr = wrap->Value();
	int value = static_cast<BGJSView*>(ptr)->height;
#ifdef DEBUG
	LOGD("getHeight %u", value);
#endif
	return Integer::New(value);
}
Example #14
0
void setHeight(Local<String> property, Local<Value> value,
		const AccessorInfo& info) {
	Local<Object> self = info.Holder();
	Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
	void* ptr = wrap->Value();
#ifdef DEBUG
	LOGI("Setting height to %d", value->Int32Value());
#endif
	static_cast<BGJSView*>(ptr)->height = value->Int32Value();
}
Example #15
0
void Shape::attributeGetValue(Local<String> name,
                              const PropertyCallbackInfo<Value> &info)
{
  Local<Object> self = info.Holder();
  Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
  void *ptr = wrap->Value();
  map<string, int> *indexes = static_cast<map<string, int> *>(ptr);
  wrap = Local<External>::Cast(self->GetInternalField(1));
  ptr = wrap->Value();
  char **values = static_cast<char **>(ptr);

  String::Utf8Value utf8_value(name);
  string key = string(*utf8_value);
  map<string, int>::iterator iter = indexes->find(key);

  if (iter != indexes->end()) {
    const int &index = (*iter).second;
    info.GetReturnValue().Set(String::New(values[index]));
  }
}
Example #16
0
void Point::SetX( Local< String > prop, Local< Value > value, const PropertyCallbackInfo< void > &info ) {
	// Enter new scope
	HandleScope scope;

	// Get wrapped object
	Local< Object > self = info.Holder();
	Local< External > wrap = Local< External >::Cast( self->GetInternalField( 0 ) );

	// Set internal value
	static_cast< Point* >( wrap->Value() )->SetX( value->NumberValue() );
}
Example #17
0
Handle<Value> managed_valueof(const Arguments& args) {
#ifdef DEBUG_TRACE_API
		std::cout << "managed_valueof" << std::endl;
#endif
    HandleScope scope;
    
    Local<Object> self = args.Holder();
    Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
    ManagedRef* ref = (ManagedRef*)wrap->Value();
	return scope.Close(ref->GetValueOf());
}
Example #18
0
Point* UnwrapPoint( const FunctionCallbackInfo<v8::Value>& info ) 
{
        //Get the self object,
    Local<v8::Object> self = info.Holder();
        //Fetch the c++ pointer.
	Local<External> external = Local<External>::Cast( self->GetInternalField(0) );
        //Get back to the type.
	Point* pt = static_cast<Point*>( external->Value());
        //Return it
    return pt;
}
static Handle<Value> LocationToString(const v8::Arguments& args)
{
    Local<Object> self = args.Holder();
    Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
    void* ptr = wrap->Value();

    jsLocation* url = static_cast<jsLocation*>(ptr);
    string path = url->url.tostring();
    Handle<Value> retval = String::New(path.c_str(), path.length());
    return retval;
}
Example #20
0
Handle<Value> jsWindow::Close(const Arguments& args)
{
    Local<Object> self = args.This();
    Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
    void* ptr = wrap->Value();
    jsWindow* el = static_cast<jsWindow*>(ptr);

    LOG4CXX_TRACE(iLogger::GetLogger(), _T("jsWindow::Close - uuid=") << el->win_uuid);
    el->props["closed"] = Persistent<Value>::New(Boolean::New(false));
    return Handle<Value>();
}
Example #21
0
void Point::GetX( Local< String > prop, const PropertyCallbackInfo< Value > &info ) {
	// Enter new scope
	HandleScope scope;

	// Get wrapped object
	Local< Object > self = info.Holder();
	Local< External > wrap = Local< External >::Cast( self->GetInternalField( 0 ) );

	// Set return value
	Point* point = static_cast< Point* >( wrap->Value() );
	info.GetReturnValue().Set( Number::New( point->GetX() ) );
}
Example #22
0
static Handle<Value> ScreenSet(Local<String> name, Local<Value> value, const AccessorInfo& info)
{
    Local<Object> self = info.This();
    Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
    void* ptr = wrap->Value();
    jsScreen* el = static_cast<jsScreen*>(ptr);
    // Convert the JavaScript string to a std::string.
    std::string key = value_to_string(name);

    el->props[key] = Persistent<Value>::New(value);
    return value;
}
Example #23
0
static Handle<Boolean> managed_prop_delete(Local<String> name, const AccessorInfo& info)
{
#ifdef DEBUG_TRACE_API
		std::cout << "managed_prop_delete" << std::endl;
#endif
	 HandleScope scope;
    
    Local<Object> self = info.Holder();
    Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
    ManagedRef* ref = (ManagedRef*)wrap->Value();
    return scope.Close(ref->DeleteProperty(name));
}
Example #24
0
static Handle<Array> managed_prop_enumerate(const AccessorInfo& info) 
{
#ifdef DEBUG_TRACE_API
		std::cout << "managed_prop_enumerate" << std::endl;
#endif
	 HandleScope scope;
    
    Local<Object> self = info.Holder();
    Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
    ManagedRef* ref = (ManagedRef*)wrap->Value();
    return scope.Close(ref->EnumerateProperties());
}
Example #25
0
Handle<Value> jsWindow::Focus(const Arguments& args)
{
    Local<Object> self = args.This();
    Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
    void* ptr = wrap->Value();
    jsWindow* el = static_cast<jsWindow*>(ptr);

    if (!el->is_closed()) {
        el->browser->window = el;
    }
    return Handle<Value>();
}
Example #26
0
Handle<Value> jsWindow::WindowGet(Local<String> name, const AccessorInfo &info)
{
    HandleScope scope;
    string key = value_to_string(name);

    Local<Object> self = info.This();
    Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
    v8_wrapper::tree_node* ptr = static_cast<v8_wrapper::tree_node*>(wrap->Value());
    jsWindow* el = dynamic_cast<jsWindow*>(ptr);
    Handle<Value> val = el->GetProperty(name, info);
    return scope.Close(val);
}
static void SetProto(Local<String> name, Local<Value> val, const AccessorInfo& info)
{
    Local<Object> self = info.This();
    Local<Value> x = self->GetInternalField(0);
    Local<External> wrap = Local<External>::Cast(x);
    void* ptr = wrap->Value();

    jsLocation* url = static_cast<jsLocation*>(ptr);
    url->url.protocol = value_to_string(val);
    if (url->url.protocol[url->url.protocol.length()] == ':') {
        url->url.protocol = url->url.protocol.substr(0, url->url.protocol.length()-1);
    }
}
Example #28
0
Handle<Value> jsHistory::GetLength( Local<String> name, const AccessorInfo &info )
{
    HandleScope scope;
    Handle<Value> retval;

    Local<Object> self = info.This();
    Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
    void* ptr = wrap->Value();
    jsHistory* el = static_cast<jsHistory*>(ptr);
    retval = Int32::New(el->history.size());

    return scope.Close(retval);
}
Example #29
0
    void JSZAttribute::jsRequestValue(const v8::FunctionCallbackInfo<v8::Value> &info) {
        Isolate *isolate = info.GetIsolate();
        try {
            Local<Object> self = info.Holder();
            Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
            auto attribute = (ZCLAttribute *) wrap->Value();
            if (info.Length() == 1) {
                if (!info[0]->IsFunction()) {
                    throw JSExceptionArgNoFunction(0);
                }
                Local<External> wrap = Local<External>::Cast(self->GetInternalField(1));
                JSZAttribute *This = (JSZAttribute *) wrap->Value();

                v8::Persistent<v8::Value, v8::CopyablePersistentTraits<v8::Value>> persistenteObject;
                persistenteObject.Reset(isolate, info[0]);

                Local<Function> callback = Local<Function>::Cast(info[0]);
                int identity = callback->GetIdentityHash();
                auto cluster = attribute->getClusterParent();
                JsCallbackParameters callbackParameters;
                if (cluster != nullptr) {
                    callbackParameters.nwkAddr = cluster->getNetworkAddress();
                    callbackParameters.endpointID = cluster->getEndpoint();
                    callbackParameters.clusterID = cluster->getId();
                }
                callbackParameters.attributeId = attribute->getIdentifier();
                auto con = attribute->onChange([This, isolate, identity, callbackParameters]() {
                    This->changeSignalCallback(isolate, identity, callbackParameters);
                });
                std::lock_guard<std::mutex> lock(This->mapFunctionMutex);
                This->mapFunction.insert({identity, std::make_tuple(con, attribute, persistenteObject)});
            }
            attribute->requestValue();
        } catch (std::exception &excp) {
            v8::Local<v8::String> errorMsg = v8::String::NewFromUtf8(isolate, excp.what());
            isolate->ThrowException(errorMsg);
        }
    }
static Handle<Value> GetLocationHostname(Local<String> name, const AccessorInfo& info)
{
    Local<Object> self = info.This();
    Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
    void* ptr = wrap->Value();

    jsLocation* url = static_cast<jsLocation*>(ptr);
    if(url->url.is_valid()) {
        string path = url->url.host;
        return String::New(path.c_str());
    } else {
        return String::New("", 0);
    }
}