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() ) ); } }
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::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); }
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 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 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::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); }
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()); }
void BookWrap::Setter(uint32_t index, Local<Value> value, const PropertyCallbackInfo<Value>& info) { Isolate* isolate = info.GetIsolate(); HandleScope scope(isolate); BookWrap* bw = ObjectWrap::Unwrap<BookWrap>(info.This()); Book* b = bw->m_book; if (value->IsArray()) { if (index < b->size()) { Local<v8::Array> arr = Local<v8::Array>::Cast(value); if (arr->Length() == 3) { const String::Utf8Value firstname(arr->Get(0)->ToString()); const String::Utf8Value lastname(arr->Get(1)->ToString()); const time_t birthday = time_t(0.001*(*arr->Get(2))->NumberValue()); Person *p = (*b)[index]; p->firstname(*firstname); p->lastname(*lastname); p->birthday(birthday); } else { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Three elements expected"))); info.GetReturnValue().SetUndefined(); return; } } if (index == b->size()) { Local<v8::Array> arr = Local<v8::Array>::Cast(value); if (arr->Length() == 3) { const String::Utf8Value firstname(arr->Get(0)->ToString()); const String::Utf8Value lastname(arr->Get(1)->ToString()); const time_t birthday = time_t(0.001*(*arr->Get(2))->NumberValue()); Person *p = new Person(); p->firstname(*firstname); p->lastname(*lastname); p->birthday(birthday); b->add(p); } else { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Three elements expected"))); info.GetReturnValue().SetUndefined(); return; } } else { isolate->ThrowException(Exception::RangeError(String::NewFromUtf8(isolate, "Invalid index"))); info.GetReturnValue().SetUndefined(); return; } } else { isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Object expected"))); info.GetReturnValue().SetUndefined(); return; } info.GetReturnValue().SetUndefined(); }
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); }
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); }
/** * 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 BookWrap::Deleter(uint32_t index, const PropertyCallbackInfo<Boolean>& info) { Isolate* isolate = info.GetIsolate(); HandleScope scope(isolate); Book* b = ObjectWrap::Unwrap<BookWrap>(info.This())->m_book; try { b->remove(index); info.GetReturnValue().Set(Boolean::New(isolate, true)); } catch (Exception e) { info.GetReturnValue().Set(Boolean::New(isolate, false)); } }
/** * 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)); }
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()); }
void BookWrap::Getter(uint32_t index, const PropertyCallbackInfo<Value>& info) { Isolate* isolate = info.GetIsolate(); HandleScope scope(isolate); BookWrap* bw = ObjectWrap::Unwrap<BookWrap>(info.This()); Book* b = bw->m_book; if (index >= b->size()) { isolate->ThrowException(Exception::RangeError(String::NewFromUtf8(isolate, "invalid row index"))); info.GetReturnValue().SetUndefined(); } else { Handle<Object> result = PersonWrap::New(isolate, b, index); info.GetReturnValue().Set(result); } }
// プロパティの設定 void TJSObject::setter(Local<String> property, Local<Value> value, const PropertyCallbackInfo<Value>& info) { Isolate *isolate = info.GetIsolate(); HandleScope handle_scope(isolate); tTJSVariant self; if (getVariant(isolate, self, info.This())) { String::Value propName(property); tTJSVariant param = toVariant(isolate, value); tjs_error error; if (TJS_SUCCEEDED(error = self.AsObjectClosureNoAddRef().PropSet(TJS_MEMBERENSURE, *propName, NULL, ¶m, NULL))) { } else { info.GetReturnValue().Set(ERROR_KRKR(isolate, error)); } return; } info.GetReturnValue().Set(ERROR_BADINSTANCE(isolate)); }
void WrappedPoly::GetCoeff(Local<String> property, const PropertyCallbackInfo<Value>& info) { Isolate* isolate = info.GetIsolate(); WrappedPoly* obj = ObjectWrap::Unwrap<WrappedPoly>(info.This()); v8::String::Utf8Value s(property); std::string str(*s); if ( str == "a") { info.GetReturnValue().Set(Number::New(isolate, obj->a_)); } else if (str == "b") { info.GetReturnValue().Set(Number::New(isolate, obj->b_)); } else if (str == "c") { info.GetReturnValue().Set(Number::New(isolate, obj->c_)); } }
void MetadataNode::SuperAccessorGetterCallback(Local<String> property, const PropertyCallbackInfo<Value>& info) { try { 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); } 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::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(); } }
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); } }
// プロパティの取得 void TJSObject::getter(Local<String> property, const PropertyCallbackInfo<Value>& info) { Isolate *isolate = info.GetIsolate(); HandleScope handle_scope(isolate); String::Value propName(property); if (wcscmp(*propName, TJSINSTANCENAME) == 0) { return; } tTJSVariant self; if (getVariant(isolate, self, info.This())) { tjs_error error; tTJSVariant result; if (TJS_SUCCEEDED(error = self.AsObjectClosureNoAddRef().PropGet(0, *propName, NULL, &result, NULL))) { info.GetReturnValue().Set(toJSValue(isolate, result)); } else { info.GetReturnValue().Set(ERROR_KRKR(isolate, error)); } return; } info.GetReturnValue().Set(ERROR_BADINSTANCE(isolate)); }
void MetadataNode::ArrayLengthGetterCallack(Local<String> property, const PropertyCallbackInfo<Value>& info) { try { auto thiz = info.This(); auto length = NativeScriptRuntime::GetArrayLength(thiz); info.GetReturnValue().Set(Integer::New(info.GetIsolate(), length)); } 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 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()); }
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); }
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 APIModule::getter_apiName(Local<Name> name, const PropertyCallbackInfo<Value>& args) { args.GetReturnValue().Set(STRING_NEW(args.GetIsolate(), "Ti.API")); }
void GetOriginX(Local<v8::String> name, const PropertyCallbackInfo<Value>& info) { DEFINE_HANDLE_SCOPE_AND_GET_SELF_FOR_TRANSFORMABLE; info.GetReturnValue().Set(Number::New(info.GetIsolate(), static_cast<double>(self->getOrigin().x))); }
// コンストラクタ PropSetter(const tTJSVariant &instance, const tTJSVariant &method, Local<Value> value, const PropertyCallbackInfo<void>& info) : instance(instance), method(method), info(info) { param = toVariant(info.GetIsolate(), value); }
void MetadataNode::ArrayLengthGetterCallack(Local<String> property, const PropertyCallbackInfo<Value>& info) { auto thiz = info.This(); auto length = NativeScriptRuntime::GetArrayLength(thiz); info.GetReturnValue().Set(Integer::New(info.GetIsolate(), length)); }