bool isMatchCandidate(ConstElementPtr e) { Context::Scope context_scope(_script->getContext()); HandleScope handleScope; Persistent<Object> plugin = getPlugin(); Handle<String> isMatchCandidateStr = String::New("isMatchCandidate"); if (plugin->Has(isMatchCandidateStr) == false) { throw HootException("Error finding 'isMatchCandidate' function."); } Handle<v8::Value> value = plugin->Get(isMatchCandidateStr); if (value->IsFunction() == false) { throw HootException("isMatchCandidate is not a function."); } Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(value); Handle<Value> jsArgs[2]; int argc = 0; jsArgs[argc++] = OsmMapJs::create(_map); jsArgs[argc++] = ElementJs::New(e); Handle<Value> f = func->Call(plugin, argc, jsArgs); return f->BooleanValue(); }
void printV8Value(Handle<Value> value, bool force=false) { Logging::Level level = force ? Logging::ERROR : Logging::INFO; if (!Logging::shouldShow(level)) return; HandleScope handleScope; if (value.IsEmpty()) Logging::log(level, "Empty handle\r\n"); else if (value->IsInt32()) Logging::log(level, "INT: %d\r\n", value->IntegerValue()); else if (value->IsNull()) Logging::log(level, "NULL (null)\r\n"); else if (value->IsUndefined()) Logging::log(level, "VOID (undefined)\r\n"); else if (value->IsBoolean()) Logging::log(level, "BOOLEAN: %d\r\n", value->BooleanValue()); else if (value->IsNumber()) Logging::log(level, "NUMBER: %f\r\n", value->NumberValue()); else if (value->IsString()) Logging::log(level, "STRING: ?\r\n"); else if (value->IsObject()) Logging::log(level, "OBJECT (object)\r\n"); else Logging::log(level, "Uncertain V8 value\n"); }
ClrFuncInvokeContext::ClrFuncInvokeContext(Handle<v8::Value> callbackOrSync) : _this(0), callback(0), uv_edge_async(0) { static MonoClassField* field; static MonoClassField* syncField; if (!field) field = mono_class_get_field_from_name(GetClrFuncInvokeContextClass(), "native"); if (!syncField) syncField = mono_class_get_field_from_name(GetClrFuncInvokeContextClass(), "Sync"); MonoObject* obj = mono_object_new(mono_domain_get(), GetClrFuncInvokeContextClass()); ClrFuncInvokeContext* thisPointer = this; mono_field_set_value(obj, field, &thisPointer); this->_this = mono_gchandle_new(obj, FALSE); // released in destructor DBG("ClrFuncInvokeContext::ClrFuncInvokeContext"); if (callbackOrSync->IsFunction()) { this->callback = new Persistent<Function>(); // released in destructor *(this->callback) = Persistent<Function>::New(Handle<Function>::Cast(callbackOrSync)); this->Sync(FALSE); } else { this->Sync(callbackOrSync->BooleanValue()); } }
void ScriptMatch::_calculateClassification(const ConstOsmMapPtr& map, Handle<Object> plugin) { Context::Scope context_scope(_script->getContext()); HandleScope handleScope; // removing these two lines causes a crash when checking for conflicts. WTF? Handle<Object> global = _script->getContext()->Global(); global->Get(String::NewSymbol("plugin")); if (_plugin->Has(String::NewSymbol("isWholeGroup"))) { Handle<Value> v = _script->call(_plugin, "isWholeGroup"); _isWholeGroup = v->BooleanValue(); } try { Handle<Value> v = _call(map, plugin); if (v.IsEmpty() || v->IsObject() == false) { throw IllegalArgumentException("Expected matchScore to return an associative array."); } QVariantMap vm = toCpp<QVariantMap>(v); // grab the match, miss, review results. If they aren't populated they get a value of 0. _p.setMatchP(_script->toNumber(v, "match", 0)); _p.setMissP(_script->toNumber(v, "miss", 0)); _p.setReviewP(_script->toNumber(v, "review", 0)); _explainText = vm["explain"].toString(); if (_explainText.isEmpty()) { _explainText = _threshold->getTypeDetail(_p); } if (_threshold->getType(_p) == MatchType::Review) { if (_explainText.isEmpty()) { throw IllegalArgumentException("If the match is a review an appropriate explanation must " "be provided (E.g. { 'review': 1, " "'explain': 'some reason' }."); } } } catch (NeedsReviewException& ex) { LOG_VAR(ex.getClassName()); _p.setReview(); _explainText = ex.getWhat(); } _p.normalize(); }
void SerializeField(google::protobuf::Message *message, const Reflection *r, const FieldDescriptor *field, Handle<Value> val) { const EnumValueDescriptor *enumValue = NULL; bool repeated = field->is_repeated(); switch (field->cpp_type()) { case FieldDescriptor::CPPTYPE_INT32: SET_VALUE(Int32, val->Int32Value()); break; case FieldDescriptor::CPPTYPE_INT64: SET_VALUE(Int64, val->NumberValue()); break; case FieldDescriptor::CPPTYPE_UINT32: SET_VALUE(UInt32, val->Uint32Value()); break; case FieldDescriptor::CPPTYPE_UINT64: SET_VALUE(UInt64, val->NumberValue()); break; case FieldDescriptor::CPPTYPE_DOUBLE: SET_VALUE(Double, val->NumberValue()); break; case FieldDescriptor::CPPTYPE_FLOAT: SET_VALUE(Float, val->NumberValue()); break; case FieldDescriptor::CPPTYPE_BOOL: SET_VALUE(Bool, val->BooleanValue()); break; case FieldDescriptor::CPPTYPE_ENUM: enumValue = val->IsNumber() ? field->enum_type()->FindValueByNumber(val->Int32Value()) : field->enum_type()->FindValueByName(*String::AsciiValue(val)); if (enumValue != NULL) SET_VALUE(Enum, enumValue); break; case FieldDescriptor::CPPTYPE_MESSAGE: if (val->IsObject()) { Type* type = protobuf->GetType(field->message_type()); type->SerializePart(repeated ? r->AddMessage(message, field) : r->MutableMessage(message, field), val.As<Object>()); } break; case FieldDescriptor::CPPTYPE_STRING: if (Buffer::HasInstance(val)) { Local<Object> buf = val->ToObject(); SET_VALUE(String, std::string(Buffer::Data(buf), Buffer::Length(buf))); } else { String::Utf8Value utf8(val); SET_VALUE(String, std::string(*utf8, utf8.length())); } break; } }
ClrFuncInvokeContext::ClrFuncInvokeContext(Handle<v8::Value> callbackOrSync) { DBG("ClrFuncInvokeContext::ClrFuncInvokeContext"); if (callbackOrSync->IsFunction()) { this->callback = new Persistent<Function>; *(this->callback) = Persistent<Function>::New(Handle<Function>::Cast(callbackOrSync)); this->Sync = false; } else { this->Sync = callbackOrSync->BooleanValue(); } this->uv_edge_async = NULL; }
int Conv::ToJavaString(JNIEnv *jniEnv, Handle<Value> val, jstring *jVal) { Handle<String> vString; Handle<Value> empty, vRes; jstring ob; char buf[64]; switch(GetNaturalType(val)) { default: { if(val->IsObject()) { /* call ToString() in javascript */ Handle<Object> oVal = val->ToObject(); Handle<Value> vToString = oVal->Get(sToString); if(!vToString.IsEmpty() && vToString->IsFunction()) { Handle<Function> fToString = Handle<Function>::Cast(vToString); vRes = fToString->CallAsFunction(oVal, 0, &empty); if(!vRes.IsEmpty() && (vRes->IsString() || vRes->IsStringObject())) { return ToJavaString(jniEnv, vRes->ToString(), jVal); } } } return ErrorType; } case TYPE_UNDEFINED: case TYPE_NULL: *jVal = 0; return OK; case TYPE_BOOL: return ToJavaString(jniEnv, (val->BooleanValue() ? "true" : "false"), jVal); case TYPE_INT: sprintf(buf, "%d", val->Int32Value()); return ToJavaString(jniEnv, buf, jVal); case TYPE_LONG: sprintf(buf, "%lld", val->IntegerValue()); return ToJavaString(jniEnv, buf, jVal); case TYPE_DOUBLE: sprintf(buf, "%g", val->NumberValue()); return ToJavaString(jniEnv, buf, jVal); case TYPE_STRING: return ToJavaString(jniEnv, val->ToString(), (jstring *)jVal); } if(ob) { *jVal = ob; return OK; } if(jniEnv->ExceptionCheck()) jniEnv->ExceptionClear(); return ErrorVM; }
ClrFuncInvokeContext::ClrFuncInvokeContext(Handle<v8::Value> callbackOrSync) { DBG("ClrFuncInvokeContext::ClrFuncInvokeContext"); if (callbackOrSync->IsFunction()) { this->callback = new Persistent<Function>; Local<Function> callbackOrSyncFunction = Handle<Function>::Cast(callbackOrSync); (this->callback)->Reset(Isolate::GetCurrent(), callbackOrSyncFunction); this->Sync = false; } else { this->Sync = callbackOrSync->BooleanValue(); } this->uv_edge_async = NULL; }
Handle<Value> COPropertyGetter(Local<String> propname, const AccessorInfo& info) { dtEntity::Component* component = UnwrapComponent(info.Holder()); if(component == NULL) { return ThrowError("Trying to access deleted component!"); } HandleScope scope; Handle<External> ext = Handle<External>::Cast(info.Data()); dtEntity::Property* prop = static_cast<dtEntity::Property*>(ext->Value()); switch(prop->GetDataType()) { case dtEntity::DataType::ARRAY: case dtEntity::DataType::VEC2: case dtEntity::DataType::VEC2D: case dtEntity::DataType::VEC3: case dtEntity::DataType::VEC3D: case dtEntity::DataType::VEC4: case dtEntity::DataType::VEC4D: case dtEntity::DataType::GROUP: case dtEntity::DataType::MATRIX: case dtEntity::DataType::QUAT: { Handle<Value> v;// = info.Holder()->GetHiddenValue(propname); if(true)//v.IsEmpty()) { v = ConvertPropertyToValue(info.Holder()->CreationContext(), prop); // info.Holder()->SetHiddenValue(propname, v); } else { Handle<Value> ret = SetValueFromProperty(prop, v); if(ret->BooleanValue() == false) { return ThrowError("Internal error: Did property change type on the fly?"); } } return scope.Close(v); } default: return scope.Close(ConvertPropertyToValue(info.Holder()->CreationContext(), prop)); } }
void v8_to_gvalue(Handle<Value> v, GValue *gv, GParamSpec *spec) { if(v->IsNumber()) { g_value_init(gv, G_TYPE_FLOAT); g_value_set_float(gv, v->NumberValue()); } else if(v->IsString()) { String::Utf8Value value(v->ToString()); if(spec->value_type == GST_TYPE_CAPS) { GstCaps* caps = gst_caps_from_string(*value); g_value_init(gv, GST_TYPE_CAPS); g_value_set_boxed(gv, caps); } else { g_value_init(gv, G_TYPE_STRING); g_value_set_string(gv, *value); } } else if(v->IsBoolean()) { g_value_init(gv, G_TYPE_BOOLEAN); g_value_set_boolean(gv, v->BooleanValue()); } return; }
bool isMatchCandidate(ConstElementPtr e) { if (_matchCandidateCache.contains(e->getElementId())) { return _matchCandidateCache[e->getElementId()]; } if (_filter && !_filter->isSatisfied(e)) { return false; } Isolate* current = v8::Isolate::GetCurrent(); HandleScope handleScope(current); Context::Scope context_scope(_script->getContext(current)); Persistent<Object> plugin(current, getPlugin(_script)); Handle<String> isMatchCandidateStr = String::NewFromUtf8(current, "isMatchCandidate"); if (ToLocal(&plugin)->Has(isMatchCandidateStr) == false) { throw HootException("Error finding 'isMatchCandidate' function."); } Handle<Value> value = ToLocal(&plugin)->Get(isMatchCandidateStr); if (value->IsFunction() == false) { throw HootException("isMatchCandidate is not a function."); } Handle<Function> func = Handle<Function>::Cast(value); Handle<Value> jsArgs[2]; int argc = 0; jsArgs[argc++] = getOsmMapJs(); jsArgs[argc++] = ElementJs::New(e); Handle<Value> f = func->Call(ToLocal(&plugin), argc, jsArgs); bool result = f->BooleanValue(); _matchCandidateCache[e->getElementId()] = result; return result; }
bool ScriptObject::extractBoolean(const Arguments &args, int index) { HandleScope handleScope; TryCatch tryCatch; // Get Boolean value Handle<Value> argValue = ScriptObject::extractArgument(args, index); if (tryCatch.HasCaught()) return false; Handle<BooleanObject> argBoolean = Handle<BooleanObject>::Cast(argValue); if (argBoolean.IsEmpty()) { Local<String> message = String::New("Argument is not a Boolean object"); throw ScriptException(v8::Exception::SyntaxError(message)); } return argBoolean->BooleanValue(); }
VALUE rr_v82rb(Handle<Value> value) { if (value.IsEmpty()) { return rr_v8_value_empty(); } if (value->IsUndefined() || value->IsNull()) { return Qnil; } if (value->IsExternal()) { return rr_reflect_v8_external(value); } if (value->IsUint32()) { return UINT2NUM(value->Uint32Value()); } if (value->IsInt32()) { return INT2FIX(value->Int32Value()); } if (value->IsBoolean()) { return value->BooleanValue() ? Qtrue : Qfalse; } if (value->IsNumber()) { return rb_float_new(value->NumberValue()); } if (value->IsString()) { return rr_reflect_v8_string(value); } if (value->IsFunction()) { return rr_reflect_v8_function(value); } if (value->IsArray()) { return rr_reflect_v8_array(value); } if (value->IsDate()) { return rr_reflect_v8_date(value); } if (value->IsObject()) { return rr_reflect_v8_object(value); } return rr_wrap_v8_value(value); }
void SerializeField(google::protobuf::Message *message, const Reflection *r, const FieldDescriptor *field, Handle<Value> val) { const EnumValueDescriptor *enumValue = NULL; bool repeated = field->is_repeated(); if (*val != NULL) { if (field->is_optional() && (val->IsNull() || val->IsUndefined())) return; switch (field->cpp_type()) { case FieldDescriptor::CPPTYPE_INT32: { if (repeated) r->AddInt32(message, field, val->Int32Value()); else r->SetInt32(message, field, val->Int32Value()); break; } case FieldDescriptor::CPPTYPE_INT64: if (repeated) if (preserve_int64 && val->IsArray()) { Local<Object> n64_array = val->ToObject(); uint64 n64; uint32 hi = n64_array->Get(0)->Uint32Value(), lo = n64_array->Get(1)->Uint32Value(); n64 = ((uint64)hi << 32) + (uint64)lo; r->AddInt64(message, field, n64); } else r->AddInt64(message, field, val->NumberValue()); else if (preserve_int64 && val->IsArray()) { Local<Object> n64_array = val->ToObject(); uint64 n64; uint32 hi = n64_array->Get(0)->Uint32Value(), lo = n64_array->Get(1)->Uint32Value(); n64 = ((uint64)hi << 32) + (uint64)lo; r->SetInt64(message, field, n64); } else r->SetInt64(message, field, val->NumberValue()); break; case FieldDescriptor::CPPTYPE_UINT32: if (repeated) r->AddUInt32(message, field, val->Uint32Value()); else r->SetUInt32(message, field, val->Uint32Value()); break; case FieldDescriptor::CPPTYPE_UINT64: if (repeated) if (preserve_int64 && val->IsArray()) { Local<Object> n64_array = val->ToObject(); uint64 n64; uint32 hi = n64_array->Get(0)->Uint32Value(), lo = n64_array->Get(1)->Uint32Value(); n64 = ((uint64)hi << 32) + (uint64)lo; r->AddUInt64(message, field, n64); } else r->AddUInt64(message, field, val->NumberValue()); else if (preserve_int64 && val->IsArray()) { Local<Object> n64_array = val->ToObject(); uint64 n64; uint32 hi = n64_array->Get(0)->Uint32Value(), lo = n64_array->Get(1)->Uint32Value(); n64 = ((uint64)hi << 32) + (uint64)lo; r->SetUInt64(message, field, n64); } else r->SetUInt64(message, field, val->NumberValue()); break; case FieldDescriptor::CPPTYPE_DOUBLE: if (repeated) r->AddDouble(message, field, val->NumberValue()); else r->SetDouble(message, field, val->NumberValue()); break; case FieldDescriptor::CPPTYPE_FLOAT: if (repeated) r->AddFloat(message, field, val->NumberValue()); else r->SetFloat(message, field, val->NumberValue()); break; case FieldDescriptor::CPPTYPE_BOOL: if (repeated) r->AddBool(message, field, val->BooleanValue()); else r->SetBool(message, field, val->BooleanValue()); break; case FieldDescriptor::CPPTYPE_ENUM: // TODO: possible memory leak? enumValue = val->IsNumber() ? field->enum_type()->FindValueByNumber(val->Int32Value()) : field->enum_type()->FindValueByName(*NanAsciiString(val)); if (enumValue != NULL) { if (repeated) r->AddEnum(message, field, enumValue); else r->SetEnum(message, field, enumValue); } break; case FieldDescriptor::CPPTYPE_MESSAGE: if (val->IsObject()) { if (repeated) SerializePart(r->AddMessage(message, field), val.As<Object>()); else SerializePart(r->MutableMessage(message, field), val.As<Object>()); } break; case FieldDescriptor::CPPTYPE_STRING: if (Buffer::HasInstance(val)) { Local<Object> buf = val->ToObject(); if (repeated) r->AddString(message, field, std::string(Buffer::Data(buf), Buffer::Length(buf))); else r->SetString(message, field, std::string(Buffer::Data(buf), Buffer::Length(buf))); break; } if (val->IsObject()) { Local<Object> val2 = val->ToObject(); Local<Value> converter = val2->Get(NanNew<String>("toProtobuf")); if (converter->IsFunction()) { Local<Function> toProtobuf = Local<Function>::Cast(converter); Local<Value> ret = toProtobuf->Call(val2,0,NULL); if (Buffer::HasInstance(ret)) { Local<Object> buf = ret->ToObject(); if (repeated) r->AddString(message, field, std::string(Buffer::Data(buf), Buffer::Length(buf))); else r->SetString(message, field, std::string(Buffer::Data(buf), Buffer::Length(buf))); break; } } } String::Utf8Value temp(val->ToString()); std::string value = std::string(*temp); if (repeated) r->AddString(message, field, value); else r->SetString(message, field, value); break; } } }
Handle<Value> MSAddSpawner(const Arguments& args) { HandleScope scope; dtEntity::MapSystem* ms = UnwrapMapSystem(args.This()); if(args.Length() != 1) { return ThrowError("Usage: addSpawner({components, name, guicategory, mapname, addtospawnerstore, iconpath})"); } Handle<Object> obj = Handle<Object>::Cast(args[0]); Handle<Value> vname = obj->Get(String::New("name")); Handle<Value> vcomponents = obj->Get(String::New("components")); if(vname.IsEmpty() || vcomponents.IsEmpty()) { return ThrowError("Usage: addSpawner({components, name, guicategory, mapname, addtospawnerstore, iconpath, parentname})"); } Handle<Value> vguicategory = obj->Get(String::New("guicategory")); Handle<Value> vmapname = obj->Get(String::New("mapname")); Handle<Value> vaddtospawnerstore = obj->Get(String::New("addtospawnerstore")); Handle<Value> viconpath = obj->Get(String::New("iconpath")); Handle<Value> vparentname = obj->Get(String::New("parentname")); std::string name = ToStdString(vname); std::string mapname = vmapname.IsEmpty() ? "" : ToStdString(vmapname); Handle<Object> components = Handle<Object>::Cast(vcomponents); dtEntity::Spawner* parent = NULL; if(!vparentname.IsEmpty() && !vparentname->IsUndefined()) { ms->GetSpawner(ToStdString(vparentname), parent); } osg::ref_ptr<dtEntity::Spawner> spawner = new dtEntity::Spawner(name, mapname, parent); if(!vguicategory.IsEmpty() && !vguicategory->IsUndefined()) { spawner->SetGUICategory(ToStdString(vguicategory)); } if(!vaddtospawnerstore.IsEmpty() && !vaddtospawnerstore->IsUndefined()) { spawner->SetAddToSpawnerStore(vaddtospawnerstore->BooleanValue()); } if(!viconpath.IsEmpty() && !viconpath->IsUndefined()) { spawner->SetIconPath(ToStdString(viconpath)); } Handle<Array> keys = components->GetPropertyNames(); for(unsigned int i = 0; i < keys->Length(); ++i) { Handle<Value> key = keys->Get(Integer::New(i)); std::string keyname = ToStdString(key); dtEntity::StringId ctype = dtEntity::SIDHash(keyname); dtEntity::ComponentPluginManager::GetInstance().StartEntitySystem(ms->GetEntityManager(), ctype); if(ms->GetEntityManager().HasEntitySystem(ctype)) { Handle<Value> val = components->Get(key); if(val->IsObject()) { Handle<Object> compobj = Handle<Object>::Cast(val); Handle<Array> compkeys = compobj->GetPropertyNames(); dtEntity::GroupProperty props; for(unsigned int j = 0; j < compkeys->Length(); ++j) { Handle<Value> compkey = compkeys->Get(Integer::New(j)); std::string compkeystr = ToStdString(compkey); Handle<Value> compval = compobj->Get(compkey); dtEntity::Property* prop = ConvertValueToProperty(compval); props.Add(dtEntity::SIDHash(compkeystr), prop); } spawner->AddComponent(ctype, props); } } } ms->AddSpawner(*spawner); return Undefined(); }
jsvalue JsEngine::AnyFromV8(Handle<Value> value, Handle<Object> thisArg) { jsvalue v; // Initialize to a generic error. v.type = JSVALUE_TYPE_UNKNOWN_ERROR; v.length = 0; v.value.str = 0; if (value->IsNull() || value->IsUndefined()) { v.type = JSVALUE_TYPE_NULL; } else if (value->IsBoolean()) { v.type = JSVALUE_TYPE_BOOLEAN; v.value.i32 = value->BooleanValue() ? 1 : 0; } else if (value->IsInt32()) { v.type = JSVALUE_TYPE_INTEGER; v.value.i32 = value->Int32Value(); } else if (value->IsUint32()) { v.type = JSVALUE_TYPE_INDEX; v.value.i64 = value->Uint32Value(); } else if (value->IsNumber()) { v.type = JSVALUE_TYPE_NUMBER; v.value.num = value->NumberValue(); } else if (value->IsString()) { v = StringFromV8(value); } else if (value->IsDate()) { v.type = JSVALUE_TYPE_DATE; v.value.num = value->NumberValue(); } else if (value->IsArray()) { Handle<Array> object = Handle<Array>::Cast(value->ToObject()); v.length = object->Length(); jsvalue* array = new jsvalue[v.length]; if (array != NULL) { for(int i = 0; i < v.length; i++) { array[i] = AnyFromV8(object->Get(i)); } v.type = JSVALUE_TYPE_ARRAY; v.value.arr = array; } } else if (value->IsFunction()) { Handle<Function> function = Handle<Function>::Cast(value); jsvalue* array = new jsvalue[2]; if (array != NULL) { array[0].value.ptr = new Persistent<Object>(Persistent<Function>::New(function)); array[0].length = 0; array[0].type = JSVALUE_TYPE_WRAPPED; if (!thisArg.IsEmpty()) { array[1].value.ptr = new Persistent<Object>(Persistent<Object>::New(thisArg)); array[1].length = 0; array[1].type = JSVALUE_TYPE_WRAPPED; } else { array[1].value.ptr = NULL; array[1].length = 0; array[1].type = JSVALUE_TYPE_NULL; } v.type = JSVALUE_TYPE_FUNCTION; v.value.arr = array; } } else if (value->IsObject()) { Handle<Object> obj = Handle<Object>::Cast(value); if (obj->InternalFieldCount() == 1) v = ManagedFromV8(obj); else v = WrappedFromV8(obj); } return v; }
int Conv::ToJavaObject(JNIEnv *jniEnv, Handle<Value> val, int expectedType, jobject *jVal) { /* empty, null and undefined convert to null for any nullable type */ if((expectedType >= TYPE__OB_START) && (val.IsEmpty() || val->IsNull() || val->IsUndefined())) { *jVal = 0; return OK; } if(isSequence(expectedType)) return ToJavaSequence(jniEnv, val, getComponentType(expectedType), (jarray *)jVal); if(isArray(expectedType)) return arrayConv->ToJavaArray(jniEnv, val, getComponentType(expectedType), jVal); if(isMap(expectedType)) return ToJavaMap(jniEnv, val, getComponentType(expectedType), jVal); if(isInterface(expectedType)) return ToJavaInterface(jniEnv, val, getClassId(expectedType), jVal); if(isDict(expectedType)) return ToJavaDict(jniEnv, val, getClassId(expectedType), jVal); HandleScope scope; jobject ob; switch(expectedType) { default: return ErrorType; case TYPE_BOOL: { bool isVoid = val.IsEmpty() ? false : val->BooleanValue(); ob = jniEnv->CallStaticObjectMethod(jni.anode.js.JSValue_Bool.class_, jni.anode.js.JSValue_Bool.ctor, isVoid); break; } case TYPE_BYTE: case TYPE_INT: { jint intValue = val.IsEmpty() ? 0 : val->Int32Value(); ob = jniEnv->CallStaticObjectMethod(jni.anode.js.JSValue_Long.class_, jni.anode.js.JSValue_Long.ctor, (jlong)intValue); break; } case TYPE_LONG: { jlong longValue = val.IsEmpty() ? 0 : val->IntegerValue(); ob = jniEnv->CallStaticObjectMethod(jni.anode.js.JSValue_Long.class_, jni.anode.js.JSValue_Long.ctor, longValue); break; } case TYPE_DOUBLE: { jdouble doubleValue = val.IsEmpty() ? 0 : val->NumberValue(); ob = jniEnv->CallStaticObjectMethod(jni.anode.js.JSValue_Double.class_, jni.anode.js.JSValue_Double.ctor, doubleValue); break; } case TYPE_STRING: return ToJavaString(jniEnv, val, (jstring *)jVal); case TYPE_DATE: return ToJavaDate(jniEnv, val, jVal); case TYPE_OBJECT: return ToNaturalJavaObject(jniEnv, val, jVal); case TYPE_OBJECT|TYPE_BOOL: { bool isVoid = val->BooleanValue(); ob = jniEnv->NewObject(jni.java.lang.Boolean.class_, jni.java.lang.Boolean.ctor, isVoid); break; } case TYPE_OBJECT|TYPE_BYTE: { jbyte byteValue = val->Int32Value(); ob = jniEnv->NewObject(jni.java.lang.Byte.class_, jni.java.lang.Byte.ctor, byteValue); break; } case TYPE_OBJECT|TYPE_INT: { jint intValue = val->Int32Value(); ob = jniEnv->NewObject(jni.java.lang.Integer.class_, jni.java.lang.Integer.ctor, intValue); break; } case TYPE_OBJECT|TYPE_LONG: { jlong longValue = val->IntegerValue(); ob = jniEnv->NewObject(jni.java.lang.Long.class_, jni.java.lang.Long.ctor, longValue); break; } case TYPE_OBJECT|TYPE_DOUBLE: { jdouble doubleValue = val->NumberValue(); ob = jniEnv->NewObject(jni.java.lang.Double.class_, jni.java.lang.Double.ctor, doubleValue); break; } } if(ob) { *jVal = ob; return OK; } if(jniEnv->ExceptionCheck()) jniEnv->ExceptionClear(); return ErrorVM; }
int Conv::ToNaturalJavaObject(JNIEnv *jniEnv, Handle<Value> val, jobject *jVal) { HandleScope scope; jobject ob = 0; int result = 0; switch(GetNaturalType(val)) { default: return ErrorInvalid; case TYPE_UNDEFINED: case TYPE_NULL: *jVal = 0; return OK; case TYPE_BOOL: ob = jniEnv->NewObject(jni.java.lang.Boolean.class_, jni.java.lang.Boolean.ctor, val->BooleanValue()); break; case TYPE_INT: ob = jniEnv->NewObject(jni.java.lang.Integer.class_, jni.java.lang.Integer.ctor, (jint)val->IntegerValue()); break; case TYPE_LONG: ob = jniEnv->NewObject(jni.java.lang.Long.class_, jni.java.lang.Long.ctor, val->IntegerValue()); break; case TYPE_DOUBLE: ob = jniEnv->NewObject(jni.java.lang.Double.class_, jni.java.lang.Double.ctor, val->NumberValue()); break; case TYPE_STRING: return ToJavaString(jniEnv, val->ToString(), (jstring *)jVal); break; case TYPE_DATE: ob = jniEnv->NewObject(jni.java.util.Date.class_, jni.java.util.Date.ctor, val->NumberValue()); break; case TYPE_FUNCTION: { Handle<Function> fVal = Handle<Function>::Cast(val->ToObject()); result = UnwrapObject(jniEnv, fVal, sObjectHiddenKey, jVal); if(result == ErrorNotfound) result = WrapV8Object(jniEnv, fVal, jVal); break; } case TYPE_ARRAY: { Handle<Array> aVal = Handle<Array>::Cast(val->ToObject()); result = UnwrapObject(jniEnv, aVal, arrayConv->getHiddenKey(), jVal); if(result == ErrorNotfound) result = arrayConv->WrapV8Array(jniEnv, aVal, jVal); break; } case TYPE_OBJECT: { Handle<Object> oVal = Handle<Object>::Cast(val->ToObject()); result = UnwrapObject(jniEnv, oVal, sObjectHiddenKey, jVal); if(result == ErrorNotfound) result = WrapV8Object(jniEnv, oVal, jVal); break; } } if(jniEnv->ExceptionCheck()) { jniEnv->ExceptionClear(); return ErrorVM; } if(ob) { *jVal = ob; return OK; } return result; }