Пример #1
0
void Shape::getProp(Local<String> property,
                    const PropertyCallbackInfo<Value>& info)
{
    HandleScope scope;
    Shape* s = ObjectWrap::Unwrap<Shape>(info.Holder());
    std::string name = TOSTR(property);
    Handle<Value> value = Undefined();

    if (name == "numvalues")
      value = Integer::New(s->get()->numvalues);
    else if (name == "numlines")
      value = Integer::New(s->get()->numlines);
    else if (name == "index")
      value = Number::New(s->get()->index);
    else if (name == "type")
      value = Integer::New(s->get()->type);
    else if (name == "tileindex")
      value = Integer::New(s->get()->tileindex);
    else if (name == "classindex")
      value = Integer::New(s->get()->classindex);
    else if (name == "text")
      value = String::New(s->get()->text);

    info.GetReturnValue().Set(value);
}
Пример #2
0
void Proxy::setIndexedProperty(uint32_t index, Local<Value> value, const PropertyCallbackInfo<Value>& info)
{
    Isolate* isolate = info.GetIsolate();
    JNIEnv* env = JNIScope::getEnv();
    if (!env) {
        LOG_JNIENV_GET_ERROR(TAG);
        // Returns undefined by default
        return;
    }

    Proxy* proxy = NativeObject::Unwrap<Proxy>(info.Holder());

    bool javaValueIsNew;
    jobject javaValue = TypeConverter::jsValueToJavaObject(isolate, env, value, &javaValueIsNew);
    jobject javaProxy = proxy->getJavaObject();
    env->CallVoidMethod(javaProxy,
                        JNIUtil::krollProxySetIndexedPropertyMethod,
                        index,
                        javaValue);

    if (!JavaObject::useGlobalRefs) {
        env->DeleteLocalRef(javaProxy);
    }
    if (javaValueIsNew) {
        env->DeleteLocalRef(javaValue);
    }

    info.GetReturnValue().Set(value);
}
Пример #3
0
void MetadataNode::FieldAccessorGetterCallback(Local<String> property, const PropertyCallbackInfo<Value>& info)
{
	try
	{
		auto thiz = info.This();
		auto fieldCallbackData = reinterpret_cast<FieldCallbackData*>(info.Data().As<External>()->Value());

		if (!fieldCallbackData->isStatic && thiz->StrictEquals(info.Holder()))
		{
			info.GetReturnValue().SetUndefined();
			return;
		}

		auto value = NativeScriptRuntime::GetJavaField(thiz, fieldCallbackData);
		info.GetReturnValue().Set(value);
	}
	catch (NativeScriptException& e)
	{
		e.ReThrowToV8();
	}
	catch (std::exception e) {
		stringstream ss;
		ss << "Error: c++ exception: " << e.what() << endl;
		NativeScriptException nsEx(ss.str());
		nsEx.ReThrowToV8();
	}
	catch (...) {
		NativeScriptException nsEx(std::string("Error: c++ exception!"));
		nsEx.ReThrowToV8();
	}
}
Пример #4
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);
  }
}
Пример #5
0
void JsHttpRequestProcessor::GetHost(Local<String> name,
                                     const PropertyCallbackInfo<Value>& info) {
  HttpRequest* request = UnwrapRequest(info.Holder());
  const string& path = request->Host();
  info.GetReturnValue().Set(
      String::NewFromUtf8(info.GetIsolate(), path.c_str(),
                          NewStringType::kNormal,
                          static_cast<int>(path.length())).ToLocalChecked());
}
Пример #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();
}
Пример #7
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));
}
Пример #8
0
void jsMyClassSetNumber(
	Local<String> property,
	Local<Value> value,
	const PropertyCallbackInfo<void>& info)
{
	Local<Object> self = info.Holder();
	ObjectWrap* pMyClass = ObjectWrap::Unwrap<ObjectWrap>(self);
	static_cast<MyClass*>(pMyClass)->setNumber(value->Int32Value());
}
Пример #9
0
void jsMyClassGetNumber(
	Local<String> property,
	const PropertyCallbackInfo<Value>& info)
{
	Local<Object> self = info.Holder();
	ObjectWrap* pMyClass = ObjectWrap::Unwrap<ObjectWrap>(self);
	int value = static_cast<MyClass*>(pMyClass)->getNumber();
	info.GetReturnValue().Set(value);
}
Пример #10
0
void jsMyClassGetName(
	Local<String> property,
	const PropertyCallbackInfo<Value>& info)
{
	Local<Object> self = info.Holder();
	ObjectWrap* pMyClass = ObjectWrap::Unwrap<ObjectWrap>(self);
	const char* name = static_cast<MyClass*>(pMyClass)->getName();
	Local<String> v8Str = String::NewFromUtf8(info.GetIsolate(), name);
	info.GetReturnValue().Set(v8Str);
}
Пример #11
0
void jsMyClassSetName(
	Local<String> property,
	Local<Value> value,
	const PropertyCallbackInfo<void>& info)
{
	Local<Object> self = info.Holder();
	ObjectWrap* pMyClass = ObjectWrap::Unwrap<ObjectWrap>(self);
	String::Utf8Value str(value);
	static_cast<MyClass*>(pMyClass)->setName(ToCString(str));
}
Пример #12
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() );
}
Пример #13
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() ) );
}
Пример #14
0
void JsHttpRequestProcessor::GetPath(Local<String> name,
                                     const PropertyCallbackInfo<Value>& info) {
  // Extract the C++ request object from the JavaScript wrapper.
  HttpRequest* request = UnwrapRequest(info.Holder());

  // Fetch the path.
  const string& path = request->Path();

  // Wrap the result in a JavaScript string and return it.
  info.GetReturnValue().Set(
      String::NewFromUtf8(info.GetIsolate(), path.c_str(),
                          NewStringType::kNormal,
                          static_cast<int>(path.length())).ToLocalChecked());
}
Пример #15
0
void Shape::setProp(Local<String> property,
                    Local<Value> value,
                    const PropertyCallbackInfo<void>& info)
{
    HandleScope scope;
    Shape* s = ObjectWrap::Unwrap<Shape>(info.Holder());
    std::string name = TOSTR(property);

    if (name == "text") {
      if (s->get()->text)
        msFree(s->get()->text);
      s->get()->text = getStringValue(value);
    }
}
Пример #16
0
void JsHttpRequestProcessor::MapSet(Local<Name> name, Local<Value> value_obj,
                                    const PropertyCallbackInfo<Value>& info) {
  if (name->IsSymbol()) return;

  // Fetch the map wrapped by this object.
  map<string, string>* obj = UnwrapMap(info.Holder());

  // Convert the key and value to std::strings.
  string key = ObjectToString(Local<String>::Cast(name));
  string value = ObjectToString(value_obj);

  // Update the map.
  (*obj)[key] = value;

  // Return the value; any non-empty handle will work.
  info.GetReturnValue().Set(value_obj);
}
Пример #17
0
void MetadataNode::FieldAccessorSetterCallback(Local<String> property, Local<Value> value, const PropertyCallbackInfo<void>& info)
{
	try
	{
		auto thiz = info.This();
		auto fieldCallbackData = reinterpret_cast<FieldCallbackData*>(info.Data().As<External>()->Value());

		if (!fieldCallbackData->isStatic && thiz->StrictEquals(info.Holder()))
		{
			info.GetReturnValue().SetUndefined();
			return;
		}

		if (fieldCallbackData->isFinal)
		{
			stringstream ss;
			ss << "You are trying to set \"" << fieldCallbackData->name << "\" which is a final field! Final fields can only be read.";
			string exceptionMessage = ss.str();

			throw NativeScriptException(exceptionMessage);
		}
		else
		{
			NativeScriptRuntime::SetJavaField(thiz, value, fieldCallbackData);
			info.GetReturnValue().Set(value);
		}
	}
	catch (NativeScriptException& e)
	{
		e.ReThrowToV8();
	}
	catch (std::exception e) {
		stringstream ss;
		ss << "Error: c++ exception: " << e.what() << endl;
		NativeScriptException nsEx(ss.str());
		nsEx.ReThrowToV8();
	}
	catch (...) {
		NativeScriptException nsEx(std::string("Error: c++ exception!"));
		nsEx.ReThrowToV8();
	}
}
Пример #18
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]));
  }
}
Пример #19
0
void JsHttpRequestProcessor::MapGet(Local<Name> name,
                                    const PropertyCallbackInfo<Value>& info) {
  if (name->IsSymbol()) return;

  // Fetch the map wrapped by this object.
  map<string, string>* obj = UnwrapMap(info.Holder());

  // Convert the JavaScript string to a std::string.
  string key = ObjectToString(Local<String>::Cast(name));

  // Look up the value if it exists using the standard STL ideom.
  map<string, string>::iterator iter = obj->find(key);

  // If the key is not present return an empty handle as signal
  if (iter == obj->end()) return;

  // Otherwise fetch the value and wrap it in a JavaScript string
  const string& value = (*iter).second;
  info.GetReturnValue().Set(
      String::NewFromUtf8(info.GetIsolate(), value.c_str(),
                          NewStringType::kNormal,
                          static_cast<int>(value.length())).ToLocalChecked());
}
Пример #20
0
void Proxy::getIndexedProperty(uint32_t index, const PropertyCallbackInfo<Value>& info)
{
    Isolate* isolate = info.GetIsolate();
    JNIEnv* env = JNIScope::getEnv();
    if (!env) {
        JSException::GetJNIEnvironmentError(isolate);
        return;
    }

    Proxy* proxy = NativeObject::Unwrap<Proxy>(info.Holder());
    jobject javaProxy = proxy->getJavaObject();
    jobject value = env->CallObjectMethod(javaProxy,
                                          JNIUtil::krollProxyGetIndexedPropertyMethod,
                                          index);

    if (!JavaObject::useGlobalRefs) {
        env->DeleteLocalRef(javaProxy);
    }

    Local<Value> result = TypeConverter::javaObjectToJsValue(isolate, env, value);
    env->DeleteLocalRef(value);

    info.GetReturnValue().Set(result);
}
Пример #21
0
void Proxy::getProperty(Local<Name> property, const PropertyCallbackInfo<Value>& args)
{
    Isolate* isolate = args.GetIsolate();
    args.GetReturnValue().Set(getPropertyForProxy(isolate, property->ToString(isolate), args.Holder()));
}
Пример #22
0
void Texture2D::GetHeight(
        Local<String> name, const PropertyCallbackInfo<Value>& args) {
    HandleScope scope(args.GetIsolate());
    auto self = GetInternalObject(args.Holder());
    args.GetReturnValue().Set(self->height());
}
void TaskStateChangeNotification::TaskStateGetter(Local<String> property, const PropertyCallbackInfo<Value>& info) {
    Local<Object> self = info.Holder();
    TaskStateChangeNotification* command=Unwrap<TaskStateChangeNotification>(self);
    int value = command->state;
    info.GetReturnValue().Set(value);
}
void TaskStateChangeNotification::TaskNameGetter(Local<String> property, const PropertyCallbackInfo<Value>& info) {
    Local<Object> self = info.Holder();
    TaskStateChangeNotification* command=Unwrap<TaskStateChangeNotification>(self);
    string value = command->task;
    info.GetReturnValue().Set(v8::String::NewFromUtf8(info.GetIsolate(), value.c_str()));
}
Пример #25
0
void SideNotification::SideGetter(Local<String> property, const PropertyCallbackInfo<Value>& info){
    Local<Object> self = info.Holder();
    SideNotification* notification=Unwrap<SideNotification>(self);
    info.GetReturnValue().Set(notification->getSide());
}