void Msg_Struct::build_buffer_arg(const Field_Info &field_info, Block_Buffer &buffer, Isolate* isolate, v8::Local<v8::Value> value) { if(field_info.field_type == "int8") { int8_t val = 0; if (value->IsInt32()) { val = value->Int32Value(isolate->GetCurrentContext()).FromJust(); } buffer.write_int8(val); } else if(field_info.field_type == "int16") { int16_t val = 0; if (value->IsInt32()) { val = value->Int32Value(isolate->GetCurrentContext()).FromJust(); } buffer.write_int16(val); } else if(field_info.field_type == "int32") { int32_t val = 0; if (value->IsInt32()) { val = value->Int32Value(isolate->GetCurrentContext()).FromJust(); } buffer.write_int32(val); } else if(field_info.field_type == "int64") { int64_t val = 0; if (value->IsNumber()) { val = value->NumberValue(isolate->GetCurrentContext()).FromJust(); } buffer.write_int64(val); } else if(field_info.field_type == "double") { double val = 0; if (value->IsNumber()) { val = value->NumberValue(isolate->GetCurrentContext()).FromJust(); } buffer.write_double(val); } else if(field_info.field_type == "bool") { bool val = 0; if (value->IsBoolean()) { val = value->BooleanValue(isolate->GetCurrentContext()).FromJust(); } buffer.write_bool(val); } else if(field_info.field_type == "string") { std::string val = ""; if (value->IsString()) { String::Utf8Value str(value->ToString(isolate->GetCurrentContext()).ToLocalChecked()); std::stringstream stream; stream << ToCString(str); val = stream.str(); } buffer.write_string(val); } else { LOG_ERROR("Can not find the field_type:%s, struct_name:%s", field_info.field_type.c_str(), struct_name().c_str()); } }
bool V8Location::namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value> data) { ASSERT(V8ClassIndex::FromInt(data->Int32Value()) == V8ClassIndex::LOCATION); // Only allow same origin access Location* imp = V8Location::toNative(host); return V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), false); }
void V8HTMLInputElement::selectionStartAttrSetterCustom(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { v8::Handle<v8::Object> holder = info.Holder(); HTMLInputElement* imp = V8HTMLInputElement::toNative(holder); if (!imp->canHaveSelection()) { throwTypeError("Accessing selectionStart on an input element that cannot have a selection.", info.GetIsolate()); return; } imp->setSelectionStart(value->Int32Value()); }
inline optional<Value> toValue(v8::Local<v8::Value> value) { if (value->IsFalse()) { return { false }; } else if (value->IsTrue()) { return { true }; } else if (value->IsString()) { return { std::string(*Nan::Utf8String(value)) }; } else if (value->IsUint32()) { return { std::uint64_t(value->Uint32Value()) }; } else if (value->IsInt32()) { return { std::int64_t(value->Int32Value()) }; } else if (value->IsNumber()) { return { value->NumberValue() }; } else { return {}; } }
//set the value of x variable inside javascript static void XSetter(v8::Local<v8::String> name,v8::Local<v8::Value> value,const v8::AccessorInfo& info) { x = value->Int32Value(); }