void MetadataNode::SuperAccessorGetterCallback(Local<String> property, const PropertyCallbackInfo<Value>& info)
{
	auto thiz = info.This();
	auto isolate = info.GetIsolate();
	auto k = ConvertToV8String("supervalue");
	auto superValue = thiz->GetHiddenValue(k).As<Object>();
	if (superValue.IsEmpty())
	{
		superValue = s_objectManager->GetEmptyObject(isolate);
		bool d = superValue->Delete(ConvertToV8String("toString"));
		d = superValue->Delete(ConvertToV8String("valueOf"));
		superValue->SetInternalField(static_cast<int>(ObjectManager::MetadataNodeKeys::CallSuper), True(isolate));

		superValue->SetPrototype(thiz->GetPrototype().As<Object>()->GetPrototype().As<Object>()->GetPrototype());
		thiz->SetHiddenValue(k, superValue);
		s_objectManager->CloneLink(thiz, superValue);

		DEBUG_WRITE("superValue.GetPrototype=%d", superValue->GetPrototype().As<Object>()->GetIdentityHash());

		auto node = GetInstanceMetadata(isolate, thiz);
		SetInstanceMetadata(isolate, superValue, node);

		thiz->SetHiddenValue(k, superValue);
	}

	info.GetReturnValue().Set(superValue);
}
Example #2
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);
}
void MetadataNode::ClassAccessorGetterCallback(Local<String> property, const PropertyCallbackInfo<Value>& info)
{
	try
	{
		auto thiz = info.This();
		auto isolate = info.GetIsolate();
		auto data = GetTypeMetadata(isolate, thiz.As<Function>());

		auto value = NativeScriptRuntime::FindClass(data->name);
		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();
	}
}
void MetadataNode::ArrayIndexedPropertySetterCallback(uint32_t index, Local<Value> value, const PropertyCallbackInfo<Value>& info)
{
	try
	{
		auto node = GetNodeFromHandle(info.This());

		NativeScriptRuntime::SetArrayElement(info.This(), index, node->m_name, value);

		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();
	}
}
Example #5
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);
}
void JSWRAPPER_BUILDPROPERTYDATA( JSWrapperData *data, const PropertyCallbackInfo<void>& info, Local<Value> *value )
{
    v8::HandleScope handle_scope( info.GetIsolate() );

    if ( (*value)->IsUndefined() )
    {
        data->setUndefined();
    } else
    if ( (*value)->IsNull() )
    {
        data->setNull();
    } else        
    if ( (*value)->IsNumber() )
    {
        data->setNumber( (*value)->ToNumber()->Value() );
    } else
    if ( (*value)->IsString() )
    {
        String::Utf8Value utf8( (*value) );
        data->setString( std::string( *utf8 ) );
    } else
    if ( (*value)->IsBoolean() )
    {
        data->setBoolean( (*value)->ToBoolean()->Value() );
    } else
    if ( (*value)->IsObject() )
    {
        data->setObject( new JSWrapperObject( info.GetIsolate(), (*value)->ToObject() ) );
    }
}
Example #7
0
void UiWindow::GetOpacity(Local<String> property, const PropertyCallbackInfo<Value>& info) {
    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope(isolate);
    UiWindow* _this = Unwrap<UiWindow>(info.This());
    double opacity = _this->GetOpacity();
    info.GetReturnValue().Set(Number::New(isolate, opacity));
}
void MetadataNode::PackageGetterCallback(Local<String> property, const PropertyCallbackInfo<Value>& info)
{
	string propName = ConvertToString(property);

	if (propName.empty())
		return;

	auto isolate = Isolate::GetCurrent();
	HandleScope handleScope(isolate);

	auto thiz = info.This();

	auto cachedItem = thiz->GetHiddenValue(property);

	if (cachedItem.IsEmpty())
	{
		auto node = GetPackageMetadata(isolate, thiz);

		uint8_t nodeType = s_metadataReader.GetNodeType(node->m_treeNode);

		DEBUG_WRITE("MetadataNode::GetterCallback: prop '%s' for node '%s' called, nodeType=%d, hash=%d", propName.c_str(), node->m_treeNode->name.c_str(), nodeType, thiz.IsEmpty() ? -42 : thiz->GetIdentityHash());

		auto child = GetChildMetadataForPackage(node, propName);
		auto foundChild = child.treeNode != nullptr;

		if (foundChild)
		{
			auto childNode = MetadataNode::GetOrCreateInternal(child.treeNode);
			cachedItem = childNode->CreateWrapper(isolate);
			thiz->SetHiddenValue(property, cachedItem);
		}
	}

	info.GetReturnValue().Set(cachedItem);
}
Example #9
0
void UiWindow::GetState(Local<String> property, const PropertyCallbackInfo<Value>& info) {
    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope(isolate);
    UiWindow* _this = Unwrap<UiWindow>(info.This());
    WINDOW_STATE state = _this->GetState();
    info.GetReturnValue().Set(Int32::New(isolate, state));
}
Example #10
0
void UiWindow::GetTopmost(Local<String> property, const PropertyCallbackInfo<Value>& info) {
    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope(isolate);
    UiWindow* _this = Unwrap<UiWindow>(info.This());
    bool topmost = _this->GetTopmost();
    info.GetReturnValue().Set(Boolean::New(isolate, topmost));
}
Example #11
0
void UiWindow::GetTop(Local<String> property, const PropertyCallbackInfo<Value>& info) {
    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope(isolate);
    UiWindow* _this = Unwrap<UiWindow>(info.This());
    WindowRect rect = _this->GetWindowRect();
    info.GetReturnValue().Set(Int32::New(isolate, rect.Top));
}
Example #12
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::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);
}
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();
	}
}
void MetadataNode::ArrayIndexedPropertySetterCallback(uint32_t index, Local<Value> value, const PropertyCallbackInfo<Value>& info)
{
	auto node = GetNodeFromHandle(info.This());

	NativeScriptRuntime::SetArrayElement(info.This(), index, node->m_name, value);

	info.GetReturnValue().Set(value);
}
Example #16
0
void UiWindow::GetTitle(Local<String> property, const PropertyCallbackInfo<Value>& info) {
    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope(isolate);
    UiWindow* _this = Unwrap<UiWindow>(info.This());
    Utf8String* title = _this->GetTitle();
    info.GetReturnValue().Set((const Handle<Value>)*title);
    delete title;
}
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);
}
void MetadataNode::ArrayIndexedPropertyGetterCallback(uint32_t index, const PropertyCallbackInfo<Value>& info)
{
	auto node = GetNodeFromHandle(info.This());

	auto element = s_getArrayElement(info.This(), index, node->m_name);

	info.GetReturnValue().Set(element);
}
Example #19
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());
}
Example #20
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);
}
Example #21
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);
}
Example #22
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));
}
Example #23
0
static void byteLength(Local<String> property, const PropertyCallbackInfo<Value>& info) {
    ClassBase* t = internalPtr<ClassBase>(info);
    if(t == 0 || t->getClassType() != CLASS_ArrayBuffer) {
        info.GetReturnValue().Set(Integer::New(0));
        return;
    }
    NodeBuffer* p = static_cast<NodeBuffer*>(t);
    info.GetReturnValue().Set(Integer::New(p->mLength));
}
void MetadataNode::ClassAccessorGetterCallback(Local<String> property, const PropertyCallbackInfo<Value>& info)
{
	auto thiz = info.This();
	auto isolate = info.GetIsolate();
	auto data = GetTypeMetadata(isolate, thiz.As<Function>());

	auto value = NativeScriptRuntime::FindClass(data->name);
	info.GetReturnValue().Set(value);
}
Example #25
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);
}
Example #26
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));
}
Example #27
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 #28
0
void BookWrap::Enumerator(const PropertyCallbackInfo<Array>& info) {
    Isolate* isolate = info.GetIsolate();
    HandleScope scope(isolate);
    
    Book* b = ObjectWrap::Unwrap<BookWrap>(info.This())->m_book;

    Handle<v8::Array> result = v8::Array::New(isolate, b->size());
    for(size_t i=0; i<b->size(); ++i) {
        result->Set(i, Integer::New(isolate, i));
    }
    info.GetReturnValue().Set(result);
}
Example #29
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();
	}
}
void MetadataNode::PackageGetterCallback(Local<String> property, const PropertyCallbackInfo<Value>& info)
{
	try
	{
		string propName = ConvertToString(property);

		if (propName.empty())
			return;

		auto isolate = Isolate::GetCurrent();
		HandleScope handleScope(isolate);

		auto thiz = info.This();

		auto cachedItem = thiz->GetHiddenValue(property);

		if (cachedItem.IsEmpty())
		{
			auto node = GetPackageMetadata(isolate, thiz);

			uint8_t nodeType = s_metadataReader.GetNodeType(node->m_treeNode);

			DEBUG_WRITE("MetadataNode::GetterCallback: prop '%s' for node '%s' called, nodeType=%d, hash=%d", propName.c_str(), node->m_treeNode->name.c_str(), nodeType, thiz.IsEmpty() ? -42 : thiz->GetIdentityHash());

			auto child = GetChildMetadataForPackage(node, propName);
			auto foundChild = child.treeNode != nullptr;

			if (foundChild)
			{
				auto childNode = MetadataNode::GetOrCreateInternal(child.treeNode);
				cachedItem = childNode->CreateWrapper(isolate);
				thiz->SetHiddenValue(property, cachedItem);
			}
		}

		info.GetReturnValue().Set(cachedItem);
	}
	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();
	}
}