void MetadataNode::InnerClassAccessorGetterCallback(Local<String> property, const PropertyCallbackInfo<Value>& info)
{
	auto isolate = info.GetIsolate();
	auto thiz = info.This();
	auto node = reinterpret_cast<MetadataNode*>(info.Data().As<External>()->Value());

	auto innerKey = ConvertToV8String("inner:" + node->m_treeNode->name);

	auto innerTypeCtorFunc = thiz->GetHiddenValue(innerKey).As<Function>();
	if (innerTypeCtorFunc.IsEmpty())
	{
		auto funcTemplate = node->GetConstructorFunctionTemplate(isolate, node->m_treeNode);
		auto ctorFunc = funcTemplate->GetFunction();

		auto innerClassData = External::New(isolate, new InnerClassData(new Persistent<Object>(isolate, thiz), node));
		auto innerTypeCtorFuncTemplate = FunctionTemplate::New(isolate, InnerClassConstructorCallback, innerClassData);
		innerTypeCtorFuncTemplate->InstanceTemplate()->SetInternalFieldCount(static_cast<int>(ObjectManager::MetadataNodeKeys::END));
		innerTypeCtorFunc = innerTypeCtorFuncTemplate->GetFunction();
		auto prototypeName = ConvertToV8String("prototype");
		auto innerTypeCtorFuncPrototype = innerTypeCtorFunc->Get(prototypeName).As<Object>();
		innerTypeCtorFuncPrototype->SetPrototype(ctorFunc->Get(prototypeName));

		thiz->SetHiddenValue(innerKey, innerTypeCtorFunc);
	}

	info.GetReturnValue().Set(innerTypeCtorFunc);
}
Пример #2
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();
	}
}
Пример #3
0
void JNIV8ClassInfo::v8JavaAccessorGetterCallback(Local<Name> property, const PropertyCallbackInfo<Value> &info) {
    JNIEnv *env = JNIWrapper::getEnvironment();
    JNILocalFrame localFrame(env, 1);

    Isolate *isolate = info.GetIsolate();
    HandleScope scope(isolate);

    v8::Local<v8::External> ext;

    ext = info.Data().As<v8::External>();
    JNIV8ObjectJavaAccessorHolder* cb = static_cast<JNIV8ObjectJavaAccessorHolder*>(ext->Value());
    if (cb->javaGetterId) {
        jobject jobj = nullptr;

        if (!cb->isStatic) {
            ext = info.This()->GetInternalField(0).As<v8::External>();
            JNIV8Object *v8Object = reinterpret_cast<JNIV8Object *>(ext->Value());

            jobj = v8Object->getJObject();
        }

        v8::Local<v8::Value> value;

        value = JNIV8Marshalling::callJavaMethod(env, cb->propertyType, cb->javaClass, cb->javaGetterId, jobj, nullptr);

        // java method could have thrown an exception; if so forward it to v8
        if(env->ExceptionCheck()) {
            BGJSV8Engine::GetInstance(isolate)->forwardJNIExceptionToV8();
            return;
        }

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

	auto value = NativeScriptRuntime::GetJavaField(thiz, fieldCallbackData);
	info.GetReturnValue().Set(value);
}
Пример #5
0
static void
gum_v8_stalker_on_get_queue_capacity (Local<String> property,
                                      const PropertyCallbackInfo<Value> & info)
{
  GumV8Stalker * self = static_cast<GumV8Stalker *> (
      info.Data ().As<External> ()->Value ());
  (void) property;
  info.GetReturnValue ().Set (self->queue_capacity);
}
Пример #6
0
static void
gum_v8_stalker_on_set_queue_capacity (Local<String> property,
                                      Local<Value> value,
                                      const PropertyCallbackInfo<void> & info)
{
  GumV8Stalker * self = static_cast<GumV8Stalker *> (
      info.Data ().As<External> ()->Value ());
  (void) property;
  self->queue_capacity = value->IntegerValue ();
}
Пример #7
0
static void
gum_v8_stalker_on_get_trust_threshold (Local<String> property,
                                       const PropertyCallbackInfo<Value> & info)
{
  GumV8Stalker * self = static_cast<GumV8Stalker *> (
      info.Data ().As<External> ()->Value ());
  GumStalker * stalker = _gum_v8_stalker_get (self);
  (void) property;
  info.GetReturnValue ().Set (gum_stalker_get_trust_threshold (stalker));
}
Пример #8
0
static void
gum_v8_stalker_on_set_trust_threshold (Local<String> property,
                                       Local<Value> value,
                                       const PropertyCallbackInfo<void> & info)
{
  GumV8Stalker * self = static_cast<GumV8Stalker *> (
      info.Data ().As<External> ()->Value ());
  GumStalker * stalker = _gum_v8_stalker_get (self);
  (void) property;
  gum_stalker_set_trust_threshold (stalker, value->IntegerValue ());
}
Пример #9
0
/**
 * TJSオブジェクト用のプロパティセッター
 * @param args 引数
 * @return 結果
 */
void
TJSInstance::tjsSetter(Local<String> property, Local<Value> value, const PropertyCallbackInfo<void>& info)
{
	Isolate *isolate = info.GetIsolate();
	HandleScope handle_scope(isolate);
	tTJSVariant instance;
	tTJSVariant method;
	if (getVariant(isolate, instance, info.This()) && getVariant(isolate, method, info.Data()->ToObject())) {
		PropSetter set(instance, method, value, info);
		set.exec();
	}
}
Пример #10
0
/**
 * TJSオブジェクト用のプロパティゲッター
 * @param args 引数
 */
void
TJSInstance::tjsGetter(Local<String> property, const PropertyCallbackInfo<Value>& info)
{
	Isolate *isolate = info.GetIsolate();
	HandleScope handle_scope(isolate);
	tTJSVariant instance;
	tTJSVariant method;
	if (getVariant(isolate, instance, info.This()) && getVariant(isolate, method, info.Data()->ToObject())) {
		PropGetter get(instance, method, info);
		info.GetReturnValue().Set(get.exec());
		return;
	}
	info.GetReturnValue().Set(ERROR_BADINSTANCE(isolate));
}
Пример #11
0
void MetadataNode::InnerClassAccessorGetterCallback(Local<String> property, const PropertyCallbackInfo<Value>& info)
{
	try
	{
		auto isolate = info.GetIsolate();
		auto thiz = info.This();
		auto node = reinterpret_cast<MetadataNode*>(info.Data().As<External>()->Value());

		auto innerKey = ConvertToV8String("inner:" + node->m_treeNode->name);

		auto innerTypeCtorFunc = thiz->GetHiddenValue(innerKey).As<Function>();
		if (innerTypeCtorFunc.IsEmpty())
		{
			auto funcTemplate = node->GetConstructorFunctionTemplate(isolate, node->m_treeNode);
			auto ctorFunc = funcTemplate->GetFunction();

			auto innerClassData = External::New(isolate, new InnerClassData(new Persistent<Object>(isolate, thiz), node));
			auto innerTypeCtorFuncTemplate = FunctionTemplate::New(isolate, InnerClassConstructorCallback, innerClassData);
			innerTypeCtorFuncTemplate->InstanceTemplate()->SetInternalFieldCount(static_cast<int>(ObjectManager::MetadataNodeKeys::END));
			innerTypeCtorFunc = innerTypeCtorFuncTemplate->GetFunction();
			auto prototypeName = ConvertToV8String("prototype");
			auto innerTypeCtorFuncPrototype = innerTypeCtorFunc->Get(prototypeName).As<Object>();
			innerTypeCtorFuncPrototype->SetPrototype(ctorFunc->Get(prototypeName));

			thiz->SetHiddenValue(innerKey, innerTypeCtorFunc);
		}

		info.GetReturnValue().Set(innerTypeCtorFunc);
	}
	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();
	}
}
Пример #12
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();
	}
}
Пример #13
0
void JNIV8ClassInfo::v8AccessorSetterCallback(Local<Name> property, Local<Value> value, const PropertyCallbackInfo<void> &info) {
    JNIEnv *env = JNIWrapper::getEnvironment();
    JNILocalFrame localFrame(env);

    HandleScope scope(info.GetIsolate());

    v8::Local<v8::External> ext;

    ext = info.Data().As<v8::External>();
    JNIV8ObjectAccessorHolder* cb = static_cast<JNIV8ObjectAccessorHolder*>(ext->Value());

    if(cb->isStatic) {
        (cb->setterCallback.s)(cb->propertyName, value, info);
    } else {
        ext = info.This()->GetInternalField(0).As<v8::External>();
        JNIV8Object *v8Object = reinterpret_cast<JNIV8Object *>(ext->Value());

        (v8Object->*(cb->setterCallback.i))(cb->propertyName, value, info);
    }
}
Пример #14
0
void MetadataNode::FieldAccessorSetterCallback(Local<String> property,Local<Value> value, const PropertyCallbackInfo<void>& info)
{
	DEBUG_WRITE("FieldAccessorSetterCallback");

	auto thiz = info.This();
	auto fieldCallbackData = reinterpret_cast<FieldCallbackData*>(info.Data().As<External>()->Value());

	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();

		ExceptionUtil::GetInstance()->ThrowExceptionToJs(exceptionMessage);
	}
	else
	{
		NativeScriptRuntime::SetJavaField(thiz, value, fieldCallbackData);
		info.GetReturnValue().Set(value);
	}
}
Пример #15
0
void Dollar::jsGetter(Local<String> property, const PropertyCallbackInfo<v8::Value>& info)
{
	auto data = info.Data();
	info.GetReturnValue().Set(data);
}
Пример #16
0
void JNIV8ClassInfo::v8JavaAccessorSetterCallback(Local<Name> property, Local<Value> value, const PropertyCallbackInfo<void> &info) {
    JNIEnv *env = JNIWrapper::getEnvironment();
    JNILocalFrame localFrame(env, 1);

    Isolate *isolate = info.GetIsolate();
    HandleScope scope(isolate);

    v8::Local<v8::External> ext;

    ext = info.Data().As<v8::External>();
    JNIV8ObjectJavaAccessorHolder* cb = static_cast<JNIV8ObjectJavaAccessorHolder*>(ext->Value());

    if (cb->javaSetterId) {
        jobject jobj = nullptr;
        jvalue jval;
        memset(&jval, 0, sizeof(jvalue));

        if (!cb->isStatic) {
            ext = info.This()->GetInternalField(0).As<v8::External>();
            JNIV8Object *v8Object = reinterpret_cast<JNIV8Object *>(ext->Value());

            jobj = v8Object->getJObject();
        }

        JNIV8MarshallingError res;
        res = JNIV8Marshalling::convertV8ValueToJavaValue(env, value, cb->propertyType, &jval);
        if(res != JNIV8MarshallingError::kOk) {
            switch(res) {
                default:
                case JNIV8MarshallingError::kWrongType:
                    ThrowV8TypeError("wrong type for property '" + cb->propertyName);
                    break;
                case JNIV8MarshallingError::kUndefined:
                    ThrowV8TypeError("property '" + cb->propertyName + "' must not be undefined");
                    break;
                case JNIV8MarshallingError::kNotNullable:
                    ThrowV8TypeError("property '" + cb->propertyName + "' is not nullable");
                    break;
                case JNIV8MarshallingError::kNoNaN:
                    ThrowV8TypeError("property '" + cb->propertyName + "' must not be NaN");
                    break;
                case JNIV8MarshallingError::kVoidNotNull:
                    ThrowV8TypeError("property '" + cb->propertyName + "' can only be null or undefined");
                    break;
                case JNIV8MarshallingError::kOutOfRange:
                    ThrowV8RangeError("assigned value '"+
                                      JNIV8Marshalling::v8string2string(value->ToString(isolate))+"' is out of range for property '" + cb->propertyName + "'");
                    break;
            }
            return;
        }

        if (jobj) {
            env->CallVoidMethodA(jobj, cb->javaSetterId, &jval);
        } else {
            env->CallStaticVoidMethodA(cb->javaClass, cb->javaSetterId, &jval);
        }

        // java method could have thrown an exception; if so forward it to v8
        if(env->ExceptionCheck()) {
            BGJSV8Engine::GetInstance(isolate)->forwardJNIExceptionToV8();
            return;
        }
    }
}