Index: src/JsValue.cpp |
=================================================================== |
--- a/src/JsValue.cpp |
+++ b/src/JsValue.cpp |
@@ -96,6 +96,15 @@ |
return UnwrapValue()->IsFunction(); |
} |
+std::tuple<bool, std::string> ConvertString(v8::Local<v8::Value> v8value) |
+{ |
+ if (!(v8value->IsString() || v8value->IsStringObject())) |
+ { |
+ return std::make_tuple(false, std::string()); |
+ } |
+ return std::make_tuple(true, AdblockPlus::Utils::FromV8String(v8value)); |
+} |
+ |
std::string AdblockPlus::JsValue::AsString() const |
{ |
const JsContext context(jsEngine); |
@@ -167,6 +176,12 @@ |
obj->Set(property, val); |
} |
+void SetPropertyOnV8Object(v8::Isolate* isolate, v8::Local<v8::Object>& target, const std::string& propertyName, const v8::Handle<v8::Value>& propertyValue) |
+{ |
+ auto v8PropertyName = AdblockPlus::Utils::ToV8String(isolate, propertyName); |
+ target->Set(v8PropertyName, propertyValue); |
+} |
+ |
v8::Local<v8::Value> AdblockPlus::JsValue::UnwrapValue() const |
{ |
return v8::Local<v8::Value>::New(jsEngine->GetIsolate(), *value); |
@@ -178,12 +193,22 @@ |
SetProperty(name, Utils::ToV8String(jsEngine->GetIsolate(), val)); |
} |
+void SetPropertyOnV8Object(v8::Isolate* isolate, v8::Local<v8::Object>& target, const std::string& propertyName, const std::string& propertyValue) |
+{ |
+ SetPropertyOnV8Object(isolate, target, propertyName, AdblockPlus::Utils::ToV8String(isolate, propertyValue)); |
+} |
+ |
void AdblockPlus::JsValue::SetProperty(const std::string& name, int64_t val) |
{ |
const JsContext context(jsEngine); |
SetProperty(name, v8::Number::New(jsEngine->GetIsolate(), val)); |
} |
+void SetPropertyOnV8Object(v8::Isolate* isolate, v8::Local<v8::Object>& target, const std::string& propertyName, int64_t propertyValue) |
+{ |
+ SetPropertyOnV8Object(isolate, target, propertyName, v8::Number::New(isolate, propertyValue)); |
+} |
+ |
void AdblockPlus::JsValue::SetProperty(const std::string& name, const JsValuePtr& val) |
{ |
const JsContext context(jsEngine); |