static void disabledAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { HTMLOptionElement* imp = V8HTMLOptionElement::toNative(info.Holder()); bool v = value->BooleanValue(); imp->setBooleanAttribute(WebCore::HTMLNames::disabledAttr, v); return; }
static void disabledAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLOptionElement.disabled._set"); HTMLOptionElement* imp = V8HTMLOptionElement::toNative(info.Holder()); bool v = value->BooleanValue(); imp->setDisabled(v); return; }
static void loopAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { AudioBufferSourceNode* imp = V8AudioBufferSourceNode::toNative(info.Holder()); bool v = value->BooleanValue(); imp->setLoop(v); return; }
static void sweepFlagAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { SVGPathSegArcRel* imp = V8SVGPathSegArcRel::toNative(info.Holder()); bool v = value->BooleanValue(); imp->setSweepFlag(v); return; }
static void sweepFlagAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.SVGPathSegArcAbs.sweepFlag._set"); SVGPathSegArcAbs* imp = V8SVGPathSegArcAbs::toNative(info.Holder()); bool v = value->BooleanValue(); imp->setSweepFlag(v); return; }
static void primaryAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLDataGridColElement.primary._set"); HTMLDataGridColElement* imp = V8HTMLDataGridColElement::toNative(info.Holder()); bool v = value->BooleanValue(); imp->setPrimary(v); return; }
static void isMapAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLImageElement.isMap._set"); HTMLImageElement* imp = V8HTMLImageElement::toNative(info.Holder()); bool v = value->BooleanValue(); imp->setBooleanAttribute(WebCore::HTMLNames::ismapAttr, v); return; }
static void multipleAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.HTMLSelectElement.multiple._set"); HTMLSelectElement* imp = V8HTMLSelectElement::toNative(info.Holder()); bool v = value->BooleanValue(); imp->setMultiple(v); return; }
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()); } }
static NativeType getNativeBool(v8::Local<v8::Value> js) { if (!js->IsBoolean()) { throw std::runtime_error("bool"); } return static_cast<NativeType>(js->BooleanValue()); }
static void baseValAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.SVGAnimatedBoolean.baseVal._set"); SVGAnimatedBoolean* imp = V8SVGAnimatedBoolean::toNative(info.Holder()); bool v = value->BooleanValue(); imp->setBaseVal(v); if (SVGElement* context = V8Proxy::svgContext(imp)) context->svgAttributeChanged(imp->associatedAttributeName()); return; }
static void qmlsqldatabase_rows_setForwardOnly(v8::Local<v8::String> /* property */, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { QV8SqlDatabaseResource *r = v8_resource_cast<QV8SqlDatabaseResource>(info.This()); if (!r || r->type != QV8SqlDatabaseResource::Rows) V8THROW_REFERENCE_VOID("Not a SQLDatabase::Rows object"); r->query.setForwardOnly(value->BooleanValue()); }
ClrFuncInvokeContext::ClrFuncInvokeContext(v8::Local<v8::Value> callbackOrSync) { DBG("ClrFuncInvokeContext::ClrFuncInvokeContext"); if (callbackOrSync->IsFunction()) { this->callback = new Nan::Persistent<v8::Function>; v8::Local<v8::Function> callbackOrSyncFunction = v8::Local<v8::Function>::Cast(callbackOrSync); (this->callback)->Reset(callbackOrSyncFunction); this->Sync = false; } else { this->Sync = callbackOrSync->BooleanValue(); } this->uv_edge_async = NULL; }
void ConvertV8ObjectToNPVariant(v8::Local<v8::Value> object, NPObject *owner, NPVariant* result) { VOID_TO_NPVARIANT(*result); // It is really the caller's responsibility to deal with the empty handle // case because there could be different actions to take in different // contexts. ASSERT(!object.IsEmpty()); if (object.IsEmpty()) return; if (object->IsNumber()) { DOUBLE_TO_NPVARIANT(object->NumberValue(), *result); } else if (object->IsBoolean()) { BOOLEAN_TO_NPVARIANT(object->BooleanValue(), *result); } else if (object->IsNull()) { NULL_TO_NPVARIANT(*result); } else if (object->IsUndefined()) { VOID_TO_NPVARIANT(*result); } else if (object->IsString()) { v8::Handle<v8::String> str = object->ToString(); uint16_t *buf = new uint16_t[str->Length()+1]; str->Write(buf); std::string utf8 = WideToUTF8(reinterpret_cast<wchar_t*>(buf)); char* utf8_chars = strdup(utf8.c_str()); STRINGN_TO_NPVARIANT(utf8_chars, utf8.length(), *result); delete[] buf; } else if (object->IsObject()) { WebCore::DOMWindow* window = WebCore::V8Proxy::retrieveWindow(); NPObject* npobject = NPN_CreateScriptObject( 0, v8::Handle<v8::Object>::Cast(object), window); if (npobject) { _NPN_RegisterObject(npobject, owner); } OBJECT_TO_NPVARIANT(npobject, *result); } }
bool V8ErrorHandler::shouldPreventDefault(v8::Local<v8::Value> returnValue) { return returnValue->IsBoolean() && returnValue->BooleanValue(); }
bool CFX_V8::ToBoolean(v8::Local<v8::Value> pValue) { if (pValue.IsEmpty()) return false; return pValue->BooleanValue(m_pIsolate.Get()); }
PJsonVal TNodeJsUtil::GetObjJson(const v8::Local<v8::Value>& Val, const bool IgnoreFunc) { AssertR(!Val->IsExternal(), "TNodeJsUtil::GetObjJson: Cannot parse v8::External!"); if (Val->IsObject()) { // if we aren't ignoring functions and the object is a function // then throw an exception EAssertR(IgnoreFunc || !Val->IsFunction(), "TNodeJsUtil::GetObjJson: Cannot parse functions!"); // parse the object if (Val->IsFunction()) { return TJsonVal::New(); } else if (Val->IsBooleanObject()) { v8::Local<v8::BooleanObject> BoolObj = v8::Local<v8::BooleanObject>::Cast(Val); return TJsonVal::NewBool(BoolObj->ValueOf()); } else if (Val->IsNumberObject()) { return TJsonVal::NewNum(Val->NumberValue()); } else if (Val->IsStringObject() || Val->IsRegExp() || Val->IsDate()) { return TJsonVal::NewStr(TStr(*v8::String::Utf8Value(Val->ToString()))); } else if (Val->IsArray()) { PJsonVal JsonArr = TJsonVal::NewArr(); v8::Array* Arr = v8::Array::Cast(*Val); for (uint i = 0; i < Arr->Length(); i++) { if (!IgnoreFunc || !Arr->Get(i)->IsFunction()) { JsonArr->AddToArr(GetObjJson(Arr->Get(i), IgnoreFunc)); } } return JsonArr; } else { // general object with fields PJsonVal JsonVal = TJsonVal::NewObj(); v8::Local<v8::Object> Obj = Val->ToObject(); v8::Local<v8::Array> FldNmV = Obj->GetOwnPropertyNames(); for (uint i = 0; i < FldNmV->Length(); i++) { const TStr FldNm(*v8::String::Utf8Value(FldNmV->Get(i)->ToString())); v8::Local<v8::Value> FldVal = Obj->Get(FldNmV->Get(i)); if (!IgnoreFunc || !FldVal->IsFunction()) { JsonVal->AddToObj(FldNm, GetObjJson(FldVal, IgnoreFunc)); } } return JsonVal; } } else { // primitive if (Val->IsUndefined()) { return TJsonVal::New(); } else if (Val->IsNull()) { return TJsonVal::NewNull(); } else if (Val->IsBoolean()) { return TJsonVal::NewBool(Val->BooleanValue()); } else if (Val->IsNumber()) { return TJsonVal::NewNum(Val->NumberValue()); } else if (Val->IsString()) { return TJsonVal::NewStr(TStr(*v8::String::Utf8Value(Val->ToString()))); } else { // TODO check for v8::Symbol throw TExcept::New("TNodeJsUtil::GetObjJson: Unknown v8::Primitive type!"); } } }
bool V8AbstractEventListener::shouldPreventDefault(v8::Local<v8::Value> returnValue) { // Prevent default action if the return value is false in accord with the spec // http://www.w3.org/TR/html5/webappapis.html#event-handler-attributes return returnValue->IsBoolean() && !returnValue->BooleanValue(); }
void V8Event::valueAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { Event* event = V8Event::toNative(info.Holder()); event->setDefaultPrevented(!value->BooleanValue()); }